fix(nuxi): always override NODE_ENV (#5417)

This commit is contained in:
Daniel Roe 2022-06-12 22:26:36 +01:00 committed by GitHub
parent 0f4fa5643f
commit a9c061cd2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import { listen } from 'listhen'
import { writeTypes } from '../utils/prepare'
import { loadKit } from '../utils/kit'
import { clearDir } from '../utils/fs'
import { overrideEnv } from '../utils/env'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -14,7 +15,7 @@ export default defineNuxtCommand({
description: 'Build nuxt and analyze production bundle (experimental)'
},
async invoke (args) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
overrideEnv('production')
const rootDir = resolve(args._[0] || '.')
const statsDir = join(rootDir, '.nuxt/stats')

View File

@ -3,6 +3,7 @@ import consola from 'consola'
import { writeTypes } from '../utils/prepare'
import { loadKit } from '../utils/kit'
import { clearDir } from '../utils/fs'
import { overrideEnv } from '../utils/env'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -12,7 +13,8 @@ export default defineNuxtCommand({
description: 'Build nuxt for production deployment'
},
async invoke (args) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
overrideEnv('production')
const rootDir = resolve(args._[0] || '.')
const { loadNuxt, buildNuxt } = await loadKit(rootDir)

View File

@ -8,6 +8,7 @@ import { showBanner } from '../utils/banner'
import { writeTypes } from '../utils/prepare'
import { loadKit } from '../utils/kit'
import { importModule } from '../utils/cjs'
import { overrideEnv } from '../utils/env'
import { defineNuxtCommand } from './index'
export default defineNuxtCommand({
@ -17,7 +18,7 @@ export default defineNuxtCommand({
description: 'Run nuxt development server'
},
async invoke (args) {
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
overrideEnv('development')
const { listen } = await import('listhen')
let currentHandler

View File

@ -0,0 +1,8 @@
export const overrideEnv = (targetEnv: string) => {
const currentEnv = process.env.NODE_ENV
if (currentEnv && currentEnv !== targetEnv) {
console.warn(`Changing \`NODE_ENV\` from \`${currentEnv}\` to \`${targetEnv}\`.`)
}
process.env.NODE_ENV = targetEnv
}