fix(kit): load .env before loading nuxt.config (#1086)

This commit is contained in:
Daniel Roe 2021-10-18 10:03:39 +01:00 committed by GitHub
parent 4f050e50bf
commit d6ad4f3b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { existsSync, promises as fsp } from 'fs'
import { promises as fsp, existsSync } from 'fs'
import { resolve } from 'pathe'
import dotenv from 'dotenv'
import { LoadNuxtConfigOptions } from './load'

View File

@ -22,9 +22,11 @@ export interface LoadNuxtConfigOptions {
}
}
export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<NuxtOptions> {
const rootDir = resolve(process.cwd(), opts.rootDir || '.')
await loadEnv(rootDir, opts.envConfig)
const nuxtConfigFile = tryResolveModule(resolve(rootDir, opts.configFile || 'nuxt.config'))
let nuxtConfig: any = {}
@ -50,8 +52,6 @@ export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
nuxtConfig.rootDir = rootDir
}
loadEnv(rootDir, opts.envConfig)
// Resolve and apply defaults
return applyDefaults(nuxtConfigSchema, nuxtConfig) as NuxtOptions
}

View File

@ -64,7 +64,7 @@ async function initNuxt (nuxt: Nuxt) {
}
export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
const options = loadNuxtConfig(opts)
const options = await loadNuxtConfig(opts)
// Temp
options.appDir = options.alias['#app'] = resolve(distDir, 'app')