How to set NODE_ENV for snowpack build? #1588
Replies: 2 comments
-
Looking at the code, it looks like the env variables are set here: Out of curiosity, what's the difference in your 'staging' and 'production' builds as far as snowpack is concerned? |
Beta Was this translation helpful? Give feedback.
-
"scripts": { https://medium.com/swlh/do-not-relay-on-node-env-hygiene-of-environment-variables-9ffba0cb5544 E: Ah, I only now learned about env-cmd... |
Beta Was this translation helpful? Give feedback.
-
Hi:
I have been struggling with setting the
NODE_ENV
variable to a custom value different thanproduction
for thesnowpack build
command.I tried many different ways:
NODE_ENV=staging npx snowpack build --clean
;NODE_ENV=staging npm run build -- --clean
;NODE_ENV=staging npm run build -- --clean
in npm's "scripts" field;cross-env NODE_ENV=staging npm run build -- --clean
in npm's "scripts" field;cross-env NODE_ENV=staging snowpack build --clean
in npm's "scripts" field;Every time, the build process ends up with setting
MODE
andNODE_ENV
toproduction
in file__snowpack__/env.js
.Whenever I substitute the command to trigger the build process with
node -e 'console.log(process.env.NODE_ENV);'
, the expected valuestaging
gets printed.What am I missing? Or, is this a bug?
As far as I understand Snowpack's source code, the actual value of
NODE_ENV
should be taken into account by the build process:https://github.com/snowpackjs/snowpack/blob/03f0c150bbac89cec4a07e007b72a2575d5a520e/snowpack/src/commands/build.ts#L62
Kind regards,
Martin
Beta Was this translation helpful? Give feedback.
All reactions