Skip to content

Commit

Permalink
fix: support set NODE_ENV in scripts when custom mode option (#8218)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored May 23, 2022
1 parent fa538cf commit adcf041
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ export async function resolveConfig(
// Note it is possible for user to have a custom mode, e.g. `staging` where
// production-like behavior is expected. This is indicated by NODE_ENV=production
// loaded from `.staging.env` and set by us as VITE_USER_NODE_ENV
const isProduction = (process.env.VITE_USER_NODE_ENV || mode) === 'production'
const isProduction =
(process.env.NODE_ENV || process.env.VITE_USER_NODE_ENV || mode) ===
'production'
if (isProduction) {
// in case default mode was not production and is overwritten
process.env.NODE_ENV = 'production'
Expand Down
3 changes: 3 additions & 0 deletions playground/optimize-deps/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs')
const vue = require('@vitejs/plugin-vue')

// Overriding the NODE_ENV set by vitest
process.env.NODE_ENV = ''

/**
* @type {import('vite').UserConfig}
*/
Expand Down

0 comments on commit adcf041

Please sign in to comment.