From d6ad4f3b16d124f01b21bb535a8e224020526cfb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 18 Oct 2021 10:03:39 +0100 Subject: [PATCH] fix(kit): load `.env` before loading `nuxt.config` (#1086) --- packages/kit/src/config/env.ts | 2 +- packages/kit/src/config/load.ts | 6 +++--- packages/nuxt3/src/core/nuxt.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/config/env.ts b/packages/kit/src/config/env.ts index f2ad896f89..5d8dd87b9b 100644 --- a/packages/kit/src/config/env.ts +++ b/packages/kit/src/config/env.ts @@ -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' diff --git a/packages/kit/src/config/load.ts b/packages/kit/src/config/load.ts index 9d6f93175d..1e5d5b4ecb 100644 --- a/packages/kit/src/config/load.ts +++ b/packages/kit/src/config/load.ts @@ -22,9 +22,11 @@ export interface LoadNuxtConfigOptions { } } -export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions { +export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise { 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 } diff --git a/packages/nuxt3/src/core/nuxt.ts b/packages/nuxt3/src/core/nuxt.ts index 63d9aebaca..024b155800 100644 --- a/packages/nuxt3/src/core/nuxt.ts +++ b/packages/nuxt3/src/core/nuxt.ts @@ -64,7 +64,7 @@ async function initNuxt (nuxt: Nuxt) { } export async function loadNuxt (opts: LoadNuxtOptions): Promise { - const options = loadNuxtConfig(opts) + const options = await loadNuxtConfig(opts) // Temp options.appDir = options.alias['#app'] = resolve(distDir, 'app')