refactor!: use DefinePlugin (again) instead of EnvironmentPlugin #4673
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theprocessobject mock, while, in Vue CLI's base config, onlyprocess.envis replaced, which has a much smaller impact.By providing the whole
process.envobject, use cases such as the abovementioned destructuring ofprocess.envare 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 theprocess.envobject - we've made that mistake toovue-cli/packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js
Lines 56 to 62 in 02859cf
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
DefinePlugininstance and use the'process.env.SOME_NAME': '"somevalue"'syntax.What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
Other information: