mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 13:15:12 +00:00
fix: do not pass separate alias
This commit is contained in:
parent
59d8427048
commit
ddc71aea48
@ -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))
|
||||
|
@ -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) {
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user