mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(kit): auto detect version if not specified
This commit is contained in:
parent
79f46748f1
commit
342bf06659
@ -2,7 +2,7 @@ import { getContext } from 'unctx'
|
||||
import type { Nuxt } from './types/nuxt'
|
||||
import type { NuxtConfig } from './types/config'
|
||||
import type { LoadNuxtConfigOptions } from './config/load'
|
||||
import { requireModule } from './utils/cjs'
|
||||
import { requireModule, tryResolveModule } from './utils/cjs'
|
||||
|
||||
/** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
|
||||
export const nuxtCtx = getContext<Nuxt>('nuxt')
|
||||
@ -41,16 +41,23 @@ export interface LoadNuxtOptions extends LoadNuxtConfigOptions {
|
||||
}
|
||||
|
||||
export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
|
||||
const resolveOpts = { paths: opts.rootDir }
|
||||
|
||||
// Detect version
|
||||
if (!opts.version) {
|
||||
opts.version = tryResolveModule('nuxt3', resolveOpts) ? 3 : 2
|
||||
}
|
||||
|
||||
// Nuxt 3
|
||||
if (opts.version !== 2) {
|
||||
const { loadNuxt } = requireModule('nuxt3', { paths: opts.rootDir })
|
||||
const { loadNuxt } = requireModule('nuxt3', resolveOpts)
|
||||
const nuxt = await loadNuxt(opts)
|
||||
return nuxt
|
||||
}
|
||||
|
||||
// Compat
|
||||
// @ts-ignore
|
||||
const { loadNuxt } = requireModule('nuxt', { paths: opts.rootDir })
|
||||
const { loadNuxt } = requireModule('nuxt', resolveOpts)
|
||||
const nuxt = await loadNuxt({
|
||||
rootDir: opts.rootDir,
|
||||
for: opts.dev ? 'dev' : 'build',
|
||||
|
Loading…
Reference in New Issue
Block a user