fix(plugin-legacy): prevent global process.env.NODE_ENV mutation #9741
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
production
and this is a problem when running several builds in series programmatically in 3rd-party CLI apps.build
functionbuild
callsresolveConfig
and passesdefaultMode
=production
resolveConfig
function overwritesprocess.env.NODE_ENV
and sets it ===production
ifmode
===production
mode
intovite build
's config, so it just defaults toproduction
and thenresolveConfig
overwrites myNODE_ENV
env variable that I had previously set on my CLINODE_ENV=development my-cli-app build
where my-cli-app will run Vite'sbuild
function several times as per my needsAdditional context
So I have a CLI app that runs Vite's
build
function 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
mode
field instead ofprocess.env.NODE_ENV
directly.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).