fix: do not pass separate alias

This commit is contained in:
Daniel Roe 2024-10-09 10:50:03 +02:00
parent 59d8427048
commit ddc71aea48
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
3 changed files with 7 additions and 17 deletions

View File

@ -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))

View File

@ -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<string, string>
}
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) {

View File

@ -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',