From f0dfb42a586ae7087b95e8fd6e3f0e94532e64ea Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 28 Apr 2021 17:51:42 +0200 Subject: [PATCH] fix(cli): support nuxt2-edge --- packages/kit/src/nuxt.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/nuxt.ts b/packages/kit/src/nuxt.ts index 5042c60708..f237c6c846 100644 --- a/packages/kit/src/nuxt.ts +++ b/packages/kit/src/nuxt.ts @@ -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, tryResolveModule } from './utils/cjs' +import { requireModule, tryRequireModule, tryResolveModule } from './utils/cjs' /** Direct access to the Nuxt context - see https://github.com/unjs/unctx. */ export const nuxtCtx = getContext('nuxt') @@ -57,7 +57,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { // Compat // @ts-ignore - const { loadNuxt } = requireModule('nuxt', resolveOpts) + const { loadNuxt } = tryRequireModule('nuxt-edge', resolveOpts) || requireModule('nuxt', resolveOpts) const nuxt = await loadNuxt({ rootDir: opts.rootDir, for: opts.dev ? 'dev' : 'build', @@ -68,14 +68,16 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { } export function buildNuxt (nuxt: Nuxt): Promise { + const resolveOpts = { paths: nuxt.options.rootDir } + // Nuxt 3 if (nuxt.options._majorVersion === 3) { - const { build } = requireModule('nuxt3', { paths: nuxt.options.rootDir }) + const { build } = requireModule('nuxt3', resolveOpts) return build(nuxt) } // Compat // @ts-ignore - const { build } = requireModule('nuxt', { paths: nuxt.options.rootDir }) + const { build } = tryRequireModule('nuxt-edge', resolveOpts) || requireModule('nuxt', resolveOpts) return build(nuxt) }