mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(nuxi): load .env
file before starting dev server (#6119)
This commit is contained in:
parent
cccafd620f
commit
40defd9f36
@ -4,6 +4,7 @@ import { debounce } from 'perfect-debounce'
|
|||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import { withTrailingSlash } from 'ufo'
|
import { withTrailingSlash } from 'ufo'
|
||||||
|
import { setupDotenv } from 'c12'
|
||||||
import { showBanner } from '../utils/banner'
|
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'
|
||||||
@ -33,6 +34,9 @@ export default defineNuxtCommand({
|
|||||||
return currentHandler ? currentHandler(req, res) : loadingHandler(req, res)
|
return currentHandler ? currentHandler(req, res) : loadingHandler(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rootDir = resolve(args._[0] || '.')
|
||||||
|
await setupDotenv({ cwd: rootDir })
|
||||||
|
|
||||||
const listener = await listen(serverHandler, {
|
const listener = await listen(serverHandler, {
|
||||||
showURL: false,
|
showURL: false,
|
||||||
clipboard: args.clipboard,
|
clipboard: args.clipboard,
|
||||||
@ -46,8 +50,6 @@ export default defineNuxtCommand({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const rootDir = resolve(args._[0] || '.')
|
|
||||||
|
|
||||||
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
||||||
|
|
||||||
let currentNuxt: Nuxt
|
let currentNuxt: Nuxt
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { existsSync, promises as fsp } from 'node:fs'
|
import { existsSync, promises as fsp } from 'node:fs'
|
||||||
import { dirname, relative } from 'node:path'
|
import { dirname, relative } from 'node:path'
|
||||||
import { execa } from 'execa'
|
import { execa } from 'execa'
|
||||||
import { loadDotenv } from 'c12'
|
import { setupDotenv } from 'c12'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ export default defineNuxtCommand({
|
|||||||
|
|
||||||
if (existsSync(resolve(rootDir, '.env'))) {
|
if (existsSync(resolve(rootDir, '.env'))) {
|
||||||
consola.info('Loading `.env`. This will not be loaded when running the server in production.')
|
consola.info('Loading `.env`. This will not be loaded when running the server in production.')
|
||||||
process.env = await loadDotenv({ cwd: rootDir, fileName: '.env', env: process.env })
|
await setupDotenv({ cwd: rootDir })
|
||||||
}
|
}
|
||||||
|
|
||||||
consola.info('Starting preview command:', nitroJSON.commands.preview)
|
consola.info('Starting preview command:', nitroJSON.commands.preview)
|
||||||
|
Loading…
Reference in New Issue
Block a user