What I've done so far:
I've been trying to setup multiple build modes like staging
, testing
, production
and development
based on NODE_ENV=production
. So I'm keeping the respective files in the root of the project folder like:
Now, all these files are having
NODE_ENV=production VUE_APP_ENV=<mode>
The document that I followed clearly states that,
vue-cli-service build --mode staging
builds a production app in staging mode, using .env, .env.staging and .env.staging.local if they are present.
Problem:
As expected, running the command npm run build --mode staging
is to give a production build with variable as listed in the .env.staging
file. However, production
variables are loaded instead of staging
.
Ref:
As expected, running the command npm run build --mode staging is to give a production build with variable as listed in the .env.staging file. However, production variables are loaded instead of staging.
This issue actually seems resolved for me as I misunderstood the documentation. NODE_ENV needs to be set explicitly and it is it works, even if using "staging":"vue-cli-service build --mode staging" in package.json.
In other words: all arguments before -- are interpreted as arguments for npm itself, not the script you are running. Sorry, something went wrong. @LinusBorg There is no way that you get a production oriented build in a staging env. I added the npm commands just to demonstrate. Sorry, something went wrong.
Setting NODE_ENV to staging makes no sense whatshowever since staging is not known by any packages, including React. Your staging environment should be as close as possible to production, meaning same build, same NODE_ENV.
You need to use the following command
npm run build -- --mode staging
All arguments before --
are considered npm
arguments and arguments after --
are passed to vue-cli-service
I was having the same problem, I figured out my problem was from using a beta version (3.0.0-beta.9
) of @vue/cli-service
so changing it to the rc version (3.0.0-rc.3
) worked. So in my package.json under devDependencies I changed it to "@vue/cli-service": "^3.0.0-rc.3"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With