yuanqing / create-figma-plugin

:battery: The comprehensive toolkit for developing plugins and widgets for Figma and FigJam
https://yuanqing.github.io/create-figma-plugin/
MIT License
902 stars 85 forks source link

Different env files for dev and prod #189

Closed oren-shlomi closed 3 months ago

oren-shlomi commented 10 months ago

Hi, how can I access different env files (ex: .dev.env , .prod.env) based on the environment? I tried to define process.env.NODE_ENV during the build script but in runtime I get an error process is not defined.

Basically I'd like to have build for DEV and build for PROD and based on the access different env files.

yuanqing commented 10 months ago

See https://github.com/yuanqing/create-figma-plugin/issues/127#issuecomment-1292150266

Then add something like this to your package.json scripts:

"build-production": "NODE_ENV=production build-figma-plugin --typecheck --minify"
oren-shlomi commented 10 months ago

See #127 (comment)

Then add something like this to your package.json scripts:

"build-production": "NODE_ENV=production build-figma-plugin --typecheck --minify"

Ok this worked, but how do I then load a different .env file based on the NODE_ENV value? For example in NODE_ENV=productionI want to load process.env.YOUR_DOMAIN from .prod.env and in NODE_ENV=dev I want to load it from .dev.env

Not sure how to configure it in build-figma-plugin-ui.js

yuanqing commented 10 months ago
  1. Does this comment help? https://github.com/yuanqing/create-figma-plugin/issues/127#issuecomment-1293194888
  2. You can write custom logic (including writing or calling your own custom esbuild plugin) in build-figma-plugin.ui.js
oren-shlomi commented 10 months ago

@yuanqing the comment doesn't help. when running the figma plugin it will read the env (NODE_ENV) incorrectly

yuanqing commented 3 months ago

I suspect that there’s something you’ve misconfigured. If you’re able to provide a repo with a simple reproduction of the issue, it’d be helpful for investigating further