mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat(nuxi): load .env
when previewing builds (#4016)
This commit is contained in:
parent
51f3bbfd23
commit
02d2d1ae35
@ -67,6 +67,10 @@ Option | Default | Description
|
||||
|
||||
This command sets `process.env.NODE_ENV` to `production`. To override, define `NODE_ENV` in a `.env` file or as command-line argument.
|
||||
|
||||
::alert{type=info}
|
||||
For convenience, in preview mode, your `.env` file will be loaded into `process.env`. (However, in production you will need to ensure your environment variables are set yourself.)
|
||||
::
|
||||
|
||||
## Info
|
||||
|
||||
```{bash}
|
||||
|
@ -24,6 +24,7 @@
|
||||
"@types/mri": "^1.1.1",
|
||||
"@types/rimraf": "^3",
|
||||
"@types/semver": "^7",
|
||||
"c12": "^0.2.4",
|
||||
"chokidar": "^3.5.3",
|
||||
"clear": "^0.1.0",
|
||||
"clipboardy": "^3.0.0",
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { existsSync, promises as fsp } from 'fs'
|
||||
import { dirname, relative } from 'path'
|
||||
import { execa } from 'execa'
|
||||
import { loadDotenv } from 'c12'
|
||||
import { resolve } from 'pathe'
|
||||
import consola from 'consola'
|
||||
|
||||
@ -34,6 +35,11 @@ export default defineNuxtCommand({
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (existsSync(resolve(rootDir, '.env'))) {
|
||||
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 })
|
||||
}
|
||||
|
||||
consola.info('Starting preview command:', nitroJSON.commands.preview)
|
||||
const [command, ...commandArgs] = nitroJSON.commands.preview.split(' ')
|
||||
consola.log('')
|
||||
|
Loading…
Reference in New Issue
Block a user