Skip to content

Commit adcf041

Browse files
authored
fix: support set NODE_ENV in scripts when custom mode option (#8218)
1 parent fa538cf commit adcf041

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/vite/src/node/config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ export async function resolveConfig(
406406
// Note it is possible for user to have a custom mode, e.g. `staging` where
407407
// production-like behavior is expected. This is indicated by NODE_ENV=production
408408
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
409-
const isProduction = (process.env.VITE_USER_NODE_ENV || mode) === 'production'
409+
const isProduction =
410+
(process.env.NODE_ENV || process.env.VITE_USER_NODE_ENV || mode) ===
411+
'production'
410412
if (isProduction) {
411413
// in case default mode was not production and is overwritten
412414
process.env.NODE_ENV = 'production'

playground/optimize-deps/vite.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const fs = require('fs')
22
const vue = require('@vitejs/plugin-vue')
33

4+
// Overriding the NODE_ENV set by vitest
5+
process.env.NODE_ENV = ''
6+
47
/**
58
* @type {import('vite').UserConfig}
69
*/

0 commit comments

Comments
 (0)