mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
fix(nuxi): always override NODE_ENV
(#5417)
This commit is contained in:
parent
0f4fa5643f
commit
a9c061cd2e
@ -5,6 +5,7 @@ import { listen } from 'listhen'
|
|||||||
import { writeTypes } from '../utils/prepare'
|
import { writeTypes } from '../utils/prepare'
|
||||||
import { loadKit } from '../utils/kit'
|
import { loadKit } from '../utils/kit'
|
||||||
import { clearDir } from '../utils/fs'
|
import { clearDir } from '../utils/fs'
|
||||||
|
import { overrideEnv } from '../utils/env'
|
||||||
import { defineNuxtCommand } from './index'
|
import { defineNuxtCommand } from './index'
|
||||||
|
|
||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
@ -14,7 +15,7 @@ export default defineNuxtCommand({
|
|||||||
description: 'Build nuxt and analyze production bundle (experimental)'
|
description: 'Build nuxt and analyze production bundle (experimental)'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
overrideEnv('production')
|
||||||
|
|
||||||
const rootDir = resolve(args._[0] || '.')
|
const rootDir = resolve(args._[0] || '.')
|
||||||
const statsDir = join(rootDir, '.nuxt/stats')
|
const statsDir = join(rootDir, '.nuxt/stats')
|
||||||
|
@ -3,6 +3,7 @@ import consola from 'consola'
|
|||||||
import { writeTypes } from '../utils/prepare'
|
import { writeTypes } from '../utils/prepare'
|
||||||
import { loadKit } from '../utils/kit'
|
import { loadKit } from '../utils/kit'
|
||||||
import { clearDir } from '../utils/fs'
|
import { clearDir } from '../utils/fs'
|
||||||
|
import { overrideEnv } from '../utils/env'
|
||||||
import { defineNuxtCommand } from './index'
|
import { defineNuxtCommand } from './index'
|
||||||
|
|
||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
@ -12,7 +13,8 @@ export default defineNuxtCommand({
|
|||||||
description: 'Build nuxt for production deployment'
|
description: 'Build nuxt for production deployment'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
overrideEnv('production')
|
||||||
|
|
||||||
const rootDir = resolve(args._[0] || '.')
|
const rootDir = resolve(args._[0] || '.')
|
||||||
|
|
||||||
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
||||||
|
@ -8,6 +8,7 @@ import { showBanner } from '../utils/banner'
|
|||||||
import { writeTypes } from '../utils/prepare'
|
import { writeTypes } from '../utils/prepare'
|
||||||
import { loadKit } from '../utils/kit'
|
import { loadKit } from '../utils/kit'
|
||||||
import { importModule } from '../utils/cjs'
|
import { importModule } from '../utils/cjs'
|
||||||
|
import { overrideEnv } from '../utils/env'
|
||||||
import { defineNuxtCommand } from './index'
|
import { defineNuxtCommand } from './index'
|
||||||
|
|
||||||
export default defineNuxtCommand({
|
export default defineNuxtCommand({
|
||||||
@ -17,7 +18,7 @@ export default defineNuxtCommand({
|
|||||||
description: 'Run nuxt development server'
|
description: 'Run nuxt development server'
|
||||||
},
|
},
|
||||||
async invoke (args) {
|
async invoke (args) {
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
|
overrideEnv('development')
|
||||||
|
|
||||||
const { listen } = await import('listhen')
|
const { listen } = await import('listhen')
|
||||||
let currentHandler
|
let currentHandler
|
||||||
|
8
packages/nuxi/src/utils/env.ts
Normal file
8
packages/nuxi/src/utils/env.ts
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user