mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +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 defu from 'defu'
|
||||
import jiti from 'jiti'
|
||||
import { applyDefaults } from 'untyped'
|
||||
import * as rc from 'rc9'
|
||||
import { tryResolveModule, requireModule, scanRequireTree } from '../utils/cjs'
|
||||
import { NuxtOptions } from '../types/config'
|
||||
import nuxtConfigSchema from './schema'
|
||||
|
||||
@ -15,28 +15,15 @@ export interface LoadNuxtConfigOptions {
|
||||
export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions {
|
||||
const rootDir = resolve(process.cwd(), opts.rootDir || '.')
|
||||
|
||||
const _require = jiti(rootDir)
|
||||
|
||||
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
|
||||
}
|
||||
const nuxtConfigFile = tryResolveModule(resolve(rootDir, opts.configFile || 'nuxt.config'))
|
||||
|
||||
let nuxtConfig: any = {}
|
||||
|
||||
if (configFile) {
|
||||
// clearRequireCache(configFile) TODO
|
||||
nuxtConfig = _require(configFile) || {}
|
||||
if (nuxtConfig.default) {
|
||||
nuxtConfig = nuxtConfig.default
|
||||
}
|
||||
if (nuxtConfigFile) {
|
||||
nuxtConfig = requireModule(nuxtConfigFile, { clearCache: true })
|
||||
nuxtConfig = { ...nuxtConfig }
|
||||
nuxtConfig._nuxtConfigFile = nuxtConfigFile
|
||||
nuxtConfig._nuxtConfigFiles = Array.from(scanRequireTree(nuxtConfigFile))
|
||||
}
|
||||
|
||||
// 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: {
|
||||
$default: ['node_modules'],
|
||||
$resolve: (val, get) => [].concat(
|
||||
@ -143,7 +135,7 @@ export default {
|
||||
},
|
||||
|
||||
watch: {
|
||||
$resolve: (_val, get) => [].concat(get._nuxtConfigFiles).filter(Boolean)
|
||||
$resolve: (val, get) => [].concat(val, get('_nuxtConfigFiles')).filter(Boolean)
|
||||
},
|
||||
|
||||
watchers: {
|
||||
|
@ -6,6 +6,8 @@ export default {
|
||||
_generate: false,
|
||||
_cli: false,
|
||||
_requiredModules: {},
|
||||
_nuxtConfigFile: undefined,
|
||||
_nuxtConfigFiles: [],
|
||||
appDir: '',
|
||||
vite: false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user