mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(cli): support nuxt2-edge
This commit is contained in:
parent
325c6b8fea
commit
f0dfb42a58
@ -2,7 +2,7 @@ import { getContext } from 'unctx'
|
|||||||
import type { Nuxt } from './types/nuxt'
|
import type { Nuxt } from './types/nuxt'
|
||||||
import type { NuxtConfig } from './types/config'
|
import type { NuxtConfig } from './types/config'
|
||||||
import type { LoadNuxtConfigOptions } from './config/load'
|
import type { LoadNuxtConfigOptions } from './config/load'
|
||||||
import { requireModule, tryResolveModule } from './utils/cjs'
|
import { requireModule, tryRequireModule, tryResolveModule } from './utils/cjs'
|
||||||
|
|
||||||
/** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
|
/** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */
|
||||||
export const nuxtCtx = getContext<Nuxt>('nuxt')
|
export const nuxtCtx = getContext<Nuxt>('nuxt')
|
||||||
@ -57,7 +57,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
|
|||||||
|
|
||||||
// Compat
|
// Compat
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { loadNuxt } = requireModule('nuxt', resolveOpts)
|
const { loadNuxt } = tryRequireModule('nuxt-edge', resolveOpts) || requireModule('nuxt', resolveOpts)
|
||||||
const nuxt = await loadNuxt({
|
const nuxt = await loadNuxt({
|
||||||
rootDir: opts.rootDir,
|
rootDir: opts.rootDir,
|
||||||
for: opts.dev ? 'dev' : 'build',
|
for: opts.dev ? 'dev' : 'build',
|
||||||
@ -68,14 +68,16 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildNuxt (nuxt: Nuxt): Promise<any> {
|
export function buildNuxt (nuxt: Nuxt): Promise<any> {
|
||||||
|
const resolveOpts = { paths: nuxt.options.rootDir }
|
||||||
|
|
||||||
// Nuxt 3
|
// Nuxt 3
|
||||||
if (nuxt.options._majorVersion === 3) {
|
if (nuxt.options._majorVersion === 3) {
|
||||||
const { build } = requireModule('nuxt3', { paths: nuxt.options.rootDir })
|
const { build } = requireModule('nuxt3', resolveOpts)
|
||||||
return build(nuxt)
|
return build(nuxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compat
|
// Compat
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { build } = requireModule('nuxt', { paths: nuxt.options.rootDir })
|
const { build } = tryRequireModule('nuxt-edge', resolveOpts) || requireModule('nuxt', resolveOpts)
|
||||||
return build(nuxt)
|
return build(nuxt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user