Skip to content

refactor!: use DefinePlugin (again) instead of EnvironmentPlugin #4673

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

Merged
merged 2 commits into from
Oct 11, 2019

Conversation

haoqunjiang
Copy link
Member

Fixes #4658

The reasoning behind the previous change was stated at #3579.

But after a closer look at the webpack documentation, I see that webpack is only against the process: { env: { NODE_ENV: JSON.stringify('production') } } style, which would break the process object mock, while, in Vue CLI's base config, only process.env is replaced, which has a much smaller impact.

By providing the whole process.env object, use cases such as the abovementioned destructuring of process.env are now supported, which is more intuitive IMO.

What might be problematic is how users customize their env vars that not started with VUE_APP. If they follow our example, they may accidentally override the process.env object - we've made that mistake too

config
.plugin('web-component-options')
.use(require('webpack/lib/DefinePlugin'), [{
'process.env': {
CUSTOM_ELEMENT_NAME: JSON.stringify(libName)
}
}])

Letting users tap into our base config is not ideal, either. Because such configuration is very tedious and tends to break between major versions like we already have done.
For this issue, we can later add a section in the documentation guiding them on how to correctly define a custom environment variable - by adding another DefinePlugin instance and use the 'process.env.SOME_NAME': '"somevalue"' syntax.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Other information:

@haoqunjiang
Copy link
Member Author

/cc @LinusBorg

@haoqunjiang haoqunjiang merged commit 01e36f3 into vuejs:dev Oct 11, 2019
@haoqunjiang haoqunjiang deleted the feat-use-define-plugin branch October 11, 2019 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destructured env vars not replaced in --modern builds
2 participants