Is it possible to set non-sensitive environmental variables (like rootUrl) in the Figma plugin? So I don’t have to manually switch variables between my dev environment and production.
Solved
Is it possible to set environmental variables in Figma plugin?
Best answer by Bahtiyar_Ahmidi
I found out a way to do this myself:
Figma uses WebPack to compile the code, and it uses HtmlWebpackPlugin, and this plugin allows us to pass extra information to ui.html.
// webpack.config.js
plugins: [
new HtmlWebpackPlugin({
template: "./src/ui.html",
filename: "ui.html",
inlineSource: ".(js)$",
chunks: ["ui"],
inject: "body",
cache: false,
// Below is the extra information that I want to pass to ui.html
env: argv.mode === "production" ? "production" : "development",
}),
],
Then we can access to this data in ui.html
// ui.html
const env = '<%= htmlWebpackPlugin.options.env %>'
const BASE_URL = env === "development" ? "http://localhost:8080" : "https://your-production-url.com"
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.