Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm run build --mode [.env.mode] not working as expected #1528

Closed
ghost opened this issue Jun 9, 2018 · 10 comments
Closed

npm run build --mode [.env.mode] not working as expected #1528

ghost opened this issue Jun 9, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented Jun 9, 2018

Version

3.0.0-beta.16

Reproduction link

https://codesandbox.io/s/qlx254n09j

Steps to reproduce

  1. Create .env.staging file in the root
  2. Add key pairs NODE_ENV=production and VUE_APP_ENV=staging in the file
  3. Add script to package.json "staging":"vue-cli-service build --mode staging",
  4. Run npm run build --mode staging
  5. Run npm run staging

What is expected?

Case 1

npm run buid --mode staging

gives a production oriented build with staging variables

Case 2

npm run staging

gives a production oriented build with staging variables

What is actually happening?

Case 1

It gives a production oriented build with production variables

Case 2

It gives a development oriented build with staging variables


I need this to deploy this to Heroku. CD/CI. I'm using postinstall script to build production, dev or staging servers based on the APP_VUE_ENV variable. Please help me. I'm super excited with Vue so far!

Reference:

https://cli.vuejs.org/guide/mode-and-env.html#example-staging-mode
#948
https://forum.vuejs.org/t/how-to-build-production-app-with-varying-config/29708

@LinusBorg
Copy link
Member

LinusBorg commented Jun 9, 2018

This is related to how npm passes arguments to scripts when using npm run

# passes the `mode` argument to npm
npm run build --mode staging

#passes the `mode` argument to vue-cli service`
npm run build -- --mode staging

In other words: all arguments before -- are interpreted as arguments for npm itself, not the script you are running.

@ghost
Copy link
Author

ghost commented Jun 9, 2018

@LinusBorg There is no way that you get a production oriented build in a staging env. I added the npm commands just to demonstrate.

@LinusBorg
Copy link
Member

Then please provide an actual reproduction so I can consider to reopen.

Please understand that we can't take your word for it and won't try to reproduce by a mere description.

@yyx990803 yyx990803 reopened this Jun 9, 2018
@yyx990803
Copy link
Member

This seems to be a regression introduced in #1503

@vuejs vuejs deleted a comment from jnarowski Jun 29, 2018
@avxkim
Copy link

avxkim commented Jun 9, 2019

@LinusBorg ghost is right, there's no way to get exact production build, but with staging/test env.

@LinusBorg
Copy link
Member

See my last comment.

@RobinManoli
Copy link

@LinusBorg this is still an issue, and the reproduction has been there since 9 Jun 2018

@LinusBorg
Copy link
Member

LinusBorg commented May 7, 2020

the codesandbox that is provided by OP does not use Vue CLI 3 (its an old Vue CLI 2 template), so is obviously not a valid reproduction.

Other reproductions were not provided.

@RobinManoli
Copy link

RobinManoli commented May 7, 2020

Ok never mind.

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

Edit: NODE_ENV works when the .env.staging file has no trailing # comments - see https://github.com/motdotla/dotenv#rules

@LinusBorg
Copy link
Member

Glad you could solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants