From ddc71aea48062f627365276264d9da079d96f180 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 9 Oct 2024 10:50:03 +0200 Subject: [PATCH] fix: do not pass separate alias --- packages/nuxt/src/core/nuxt.ts | 2 +- packages/nuxt/src/core/plugins/virtual.ts | 20 +++++--------------- packages/vite/src/client.ts | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 5567898427..d0b59b11df 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -243,7 +243,7 @@ async function initNuxt (nuxt: Nuxt) { // Support Nuxt VFS addBuildPlugin(VirtualFSPlugin(nuxt, { mode: 'server' }), { client: false }) - addBuildPlugin(VirtualFSPlugin(nuxt, { mode: 'client', alias: { '#internal/nitro': '#build/nitro.client.mjs' } }), { server: false }) + addBuildPlugin(VirtualFSPlugin(nuxt, { mode: 'client' }), { server: false }) // Add plugin normalization plugin addBuildPlugin(RemovePluginMetadataPlugin(nuxt)) diff --git a/packages/nuxt/src/core/plugins/virtual.ts b/packages/nuxt/src/core/plugins/virtual.ts index 28f88ea1aa..60bd76a974 100644 --- a/packages/nuxt/src/core/plugins/virtual.ts +++ b/packages/nuxt/src/core/plugins/virtual.ts @@ -1,4 +1,4 @@ -import { findPath, resolveAlias, useNuxt } from '@nuxt/kit' +import { resolveAlias, useNuxt } from '@nuxt/kit' import { dirname, isAbsolute, resolve } from 'pathe' import { createUnplugin } from 'unplugin' @@ -6,12 +6,10 @@ const PREFIX = '\0virtual:nuxt:' interface VirtualFSPluginOptions { mode: 'client' | 'server' - alias?: Record } export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOptions) => createUnplugin(() => { const extensions = ['', ...nuxt.options.extensions] - const alias = { ...nuxt.options.alias, ...options.alias } const resolveWithExt = (id: string) => { for (const suffix of ['', '.' + options.mode]) { @@ -26,10 +24,8 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption return { name: 'nuxt:virtual', - enforce: 'pre', - async resolveId (id, importer) { - const _id = id - id = resolveAlias(id, alias) + resolveId (id, importer) { + id = resolveAlias(id, nuxt.options.alias) if (process.platform === 'win32' && isAbsolute(id)) { // Add back C: prefix on Windows @@ -41,23 +37,17 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption return PREFIX + resolvedId } - if (importer && /^\.{1,2}\//.test(id)) { + if (importer && /^\.{1,2}[\\/]/.test(id)) { const path = resolve(dirname(withoutPrefix(importer)), id) const resolved = resolveWithExt(path) if (resolved) { return PREFIX + resolved } - if (importer.startsWith(PREFIX)) { - const fsPath = await findPath(path, { fallbackToOriginal: false }) - if (fsPath) { - return fsPath - } - } } }, loadInclude (id) { - return id.startsWith(PREFIX) + return id.startsWith(PREFIX) && withoutPrefix(id) in nuxt.vfs }, load (id) { diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 2bbfa6a546..e68ba85593 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -109,7 +109,7 @@ export async function buildClient (ctx: ViteBuildContext) { alias: { ...nodeCompat.alias, ...ctx.config.resolve?.alias, - '#internal/nitro': '#build/nitro.client.mjs', + '#internal/nitro': join(ctx.nuxt.options.buildDir, 'nitro.client.mjs'), }, dedupe: [ 'vue',