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

ENV/mode loading timing problem #959

Closed
hengwei-lhm opened this issue Mar 8, 2018 · 6 comments
Closed

ENV/mode loading timing problem #959

hengwei-lhm opened this issue Mar 8, 2018 · 6 comments

Comments

@hengwei-lhm
Copy link

hengwei-lhm commented Mar 8, 2018

Version

3.0.0-beta.5

Reproduction link

https://codepen.io/anon/pen/yKBxvQ

Steps to reproduce

1 .vue.config.js
module.exports = {
baseUrl: process.env.NODE_ENV === 'production' ? "{{.urlPrefix}}" : "debug",
}
2 .run vue-cli-service build --mode production in command line

What is expected?

run vue-cli-service build --mode production in command line ; process.env.NODE_ENV === 'production'

What is actually happening?

process.env.NODE_ENV === undefined

@jkzing
Copy link
Member

jkzing commented Mar 8, 2018

Um...seems to be a bug, user options is loaded before NODE_ENV initialized.

@LinusBorg
Copy link
Member

We might have an architectural issue here. The build command (which is setting the production mode) is implemented as a plugin (like all other commands), and plugins receive the loaded config in their arguments - so the config has to be loaded before the build command can be run.

This might not be a simple change this line type of bugfix.

@posva
Copy link
Member

posva commented Mar 8, 2018

As a workaround, I remember putting NODE_ENV=production in front of the existing build command

@jkzing
Copy link
Member

jkzing commented Mar 9, 2018

@LinusBorg , Yes, I managed to find a clean fix and realized it's not that simple...Actually we can pass all user arguments in to Service when calling its constructor. However commands like serve and build have their own default arguments, which can not simply be touched during Service initialize stage.

@xvaara
Copy link

xvaara commented Apr 4, 2018

As a workaround at the moment I'm using process.env.npm_lifecycle_event === 'build' to differentiate between dev/build.

@yyx990803 yyx990803 changed the title process.env.NODE_ENV is undefined ENV loading timing problem Apr 27, 2018
@yyx990803 yyx990803 changed the title ENV loading timing problem ENV/mode loading timing problem Apr 27, 2018
@laomao800
Copy link

I'm using a similar way as @xvaara but match the process.env.npm_lifecycle_script to get the mode value, and use Dotenv to load the .env.[mode] file at the vue.config.js 's beginning.

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

No branches or pull requests

7 participants