mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(kit): properly resolve _nuxtConfigFiles
This commit is contained in:
parent
94d36976c7
commit
5ed6fa7612
@ -1,8 +1,8 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
import jiti from 'jiti'
|
|
||||||
import { applyDefaults } from 'untyped'
|
import { applyDefaults } from 'untyped'
|
||||||
import * as rc from 'rc9'
|
import * as rc from 'rc9'
|
||||||
|
import { tryResolveModule, requireModule, scanRequireTree } from '../utils/cjs'
|
||||||
import { NuxtOptions } from '../types/config'
|
import { NuxtOptions } from '../types/config'
|
||||||
import nuxtConfigSchema from './schema'
|
import nuxtConfigSchema from './schema'
|
||||||
|
|
||||||
@ -15,28 +15,15 @@ export interface LoadNuxtConfigOptions {
|
|||||||
export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
|
export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
|
||||||
const rootDir = resolve(process.cwd(), opts.rootDir || '.')
|
const rootDir = resolve(process.cwd(), opts.rootDir || '.')
|
||||||
|
|
||||||
const _require = jiti(rootDir)
|
const nuxtConfigFile = tryResolveModule(resolve(rootDir, opts.configFile || 'nuxt.config'))
|
||||||
|
|
||||||
let configFile
|
|
||||||
try {
|
|
||||||
configFile = _require.resolve(resolve(rootDir, opts.configFile || 'nuxt.config'))
|
|
||||||
} catch (e) {
|
|
||||||
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
||||||
throw (e)
|
|
||||||
}
|
|
||||||
// Skip if cannot resolve
|
|
||||||
configFile = undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
let nuxtConfig: any = {}
|
let nuxtConfig: any = {}
|
||||||
|
|
||||||
if (configFile) {
|
if (nuxtConfigFile) {
|
||||||
// clearRequireCache(configFile) TODO
|
nuxtConfig = requireModule(nuxtConfigFile, { clearCache: true })
|
||||||
nuxtConfig = _require(configFile) || {}
|
|
||||||
if (nuxtConfig.default) {
|
|
||||||
nuxtConfig = nuxtConfig.default
|
|
||||||
}
|
|
||||||
nuxtConfig = { ...nuxtConfig }
|
nuxtConfig = { ...nuxtConfig }
|
||||||
|
nuxtConfig._nuxtConfigFile = nuxtConfigFile
|
||||||
|
nuxtConfig._nuxtConfigFiles = Array.from(scanRequireTree(nuxtConfigFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine configs
|
// Combine configs
|
||||||
|
@ -88,14 +88,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_nuxtConfigFile: {
|
|
||||||
$resolve: (val, get) => resolve(get('rootDir'), val || 'nuxt.config.js')
|
|
||||||
},
|
|
||||||
|
|
||||||
_nuxtConfigFiles: {
|
|
||||||
$resolve: (val, get) => [].concat(get('_nuxtConfigFile'), val).filter(Boolean)
|
|
||||||
},
|
|
||||||
|
|
||||||
modulesDir: {
|
modulesDir: {
|
||||||
$default: ['node_modules'],
|
$default: ['node_modules'],
|
||||||
$resolve: (val, get) => [].concat(
|
$resolve: (val, get) => [].concat(
|
||||||
@ -143,7 +135,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
$resolve: (_val, get) => [].concat(get._nuxtConfigFiles).filter(Boolean)
|
$resolve: (val, get) => [].concat(val, get('_nuxtConfigFiles')).filter(Boolean)
|
||||||
},
|
},
|
||||||
|
|
||||||
watchers: {
|
watchers: {
|
||||||
|
@ -6,6 +6,8 @@ export default {
|
|||||||
_generate: false,
|
_generate: false,
|
||||||
_cli: false,
|
_cli: false,
|
||||||
_requiredModules: {},
|
_requiredModules: {},
|
||||||
|
_nuxtConfigFile: undefined,
|
||||||
|
_nuxtConfigFiles: [],
|
||||||
appDir: '',
|
appDir: '',
|
||||||
vite: false
|
vite: false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user