Currently, I have to add cross-env into build script every time. (cross-env NODE_ENV=production vue-cli-service build).
If I don't add it, build script will not minify files and extract CSS. (My laptop set NODE_ENV to development.)
It should be great if vue-cli automatically define NODE_ENV to production when use vue-cli-service build with production mode. (It's default)
Vue CLI respects existing env vars. May I ask why do you set a default NODE_ENV?
@yyx990803 Because I use Node for development and I'm too lazy to set NODE_ENV in project manually. So, I set it globally. 馃槄
Vue CLI respects existing env vars
Did you mean that vue-cli-service build will use mode to determine minimization?
But I can't make vue-cli-service build minimize all files for me via vue-cli-service build or vue-cli-service build --mode production.
It alway output single dist/app.js
On my PowerShell:
Write-Host $env:NODE_ENV
development
Without mode:
npx vue-cli-service build
dist\app.js
With mode:
npx vue-cli-service build --mode production
dist\app.js
With cross-env:
npx cross-env NODE_ENV=production vue-cli-service build
dist\js\chunk-vendors.34beec8f.js
dist\js\app.77596ca4.js
dist\css\app.fa853a0f.css
dist\css\chunk-vendors.b30ce958.css
@Akryum Thank you very much.
That should be solution but it doesn't work as expect. Weird 馃
.env.production (at project root):
NODE_ENV=production
Without mode:
npx vue-cli-service build
dist\app.js
With mode:
npx vue-cli-service build --mode production
dist\app.js
I assume you still have NODE_ENV defined globally on your system?
You can't overwrite an environment variable set on your system with one in an .env file. As Evan alreay explained, and as the documentation explains (I think) - if you have set an environment variable, vue-cli will never overwrite that.
That's why cross-env works. it changes the environment variable on your system before vue-cli-service runs.
It's specifically designed like that so people can overwrite stuff with environment variables, which is quite often required in CI/CD environments.
@LinusBorg Yes. I've defined it globally.
It's clear now. Thank you for clarification.
I will use cross-env to force overwrite it.
Thank you very much, everyone. 馃帀
Most helpful comment
I assume you still have NODE_ENV defined globally on your system?
You can't overwrite an environment variable set on your system with one in an
.envfile. As Evan alreay explained, and as the documentation explains (I think) - if you have set an environment variable, vue-cli will never overwrite that.That's why cross-env works. it changes the environment variable on your system before vue-cli-service runs.
It's specifically designed like that so people can overwrite stuff with environment variables, which is quite often required in CI/CD environments.