Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/nuxi/src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxi/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxi/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/nuxi/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -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
}