fix(plugin-legacy): prevent global process.env.NODE_ENV mutation#9741
Merged
patak-cat merged 4 commits intovitejs:mainfrom Aug 24, 2022
Merged
fix(plugin-legacy): prevent global process.env.NODE_ENV mutation#9741patak-cat merged 4 commits intovitejs:mainfrom
patak-cat merged 4 commits intovitejs:mainfrom
Conversation
bluwy
reviewed
Aug 21, 2022
Member
bluwy
left a comment
There was a problem hiding this comment.
Thanks for the explanation! This make sense to me and is definitely an issue in the bigger picture. We may be changing this in the future from this discussion but for now this fix looks fine to me.
The caveat now is that the polyfill chunk may be built in development mode, but I don't think it's a big issue if the whole bundle is built in development mode in the first place.
bluwy
approved these changes
Aug 24, 2022
patak-cat
approved these changes
Aug 24, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
TL;DR Enabling the legacy plugin will always cause process.env.NODE_ENV to mutate to
productionand this is a problem when running several builds in series programmatically in 3rd-party CLI apps.buildfunctionbuildcallsresolveConfigand passesdefaultMode=productionresolveConfigfunction overwritesprocess.env.NODE_ENVand sets it ===productionifmode===productionmodeintovite build's config, so it just defaults toproductionand thenresolveConfigoverwrites myNODE_ENVenv variable that I had previously set on my CLINODE_ENV=development my-cli-app buildwhere my-cli-app will run Vite'sbuildfunction several times as per my needsAdditional context
So I have a CLI app that runs Vite's
buildfunction several times one after another, generally most of the time it runs a build for a client set of assets, and another time for the SSR/server version. But when the legacy plugin is activated, it runs after the client build and overrides myNODE_ENV=development, which results in the SSR/server build always building in PROD mode.PS So I messed up the first commit's message, is it possible to squash and set another commit message that better describes the issue?!
PPS Updated PR to use the resolved vite config
modefield instead ofprocess.env.NODE_ENVdirectly.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).