mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 22:55:13 +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
|
// Support Nuxt VFS
|
||||||
addBuildPlugin(VirtualFSPlugin(nuxt, { mode: 'server' }), { client: false })
|
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
|
// Add plugin normalization plugin
|
||||||
addBuildPlugin(RemovePluginMetadataPlugin(nuxt))
|
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 { dirname, isAbsolute, resolve } from 'pathe'
|
||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
|
|
||||||
@ -6,12 +6,10 @@ const PREFIX = '\0virtual:nuxt:'
|
|||||||
|
|
||||||
interface VirtualFSPluginOptions {
|
interface VirtualFSPluginOptions {
|
||||||
mode: 'client' | 'server'
|
mode: 'client' | 'server'
|
||||||
alias?: Record<string, string>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOptions) => createUnplugin(() => {
|
export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOptions) => createUnplugin(() => {
|
||||||
const extensions = ['', ...nuxt.options.extensions]
|
const extensions = ['', ...nuxt.options.extensions]
|
||||||
const alias = { ...nuxt.options.alias, ...options.alias }
|
|
||||||
|
|
||||||
const resolveWithExt = (id: string) => {
|
const resolveWithExt = (id: string) => {
|
||||||
for (const suffix of ['', '.' + options.mode]) {
|
for (const suffix of ['', '.' + options.mode]) {
|
||||||
@ -26,10 +24,8 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'nuxt:virtual',
|
name: 'nuxt:virtual',
|
||||||
enforce: 'pre',
|
resolveId (id, importer) {
|
||||||
async resolveId (id, importer) {
|
id = resolveAlias(id, nuxt.options.alias)
|
||||||
const _id = id
|
|
||||||
id = resolveAlias(id, alias)
|
|
||||||
|
|
||||||
if (process.platform === 'win32' && isAbsolute(id)) {
|
if (process.platform === 'win32' && isAbsolute(id)) {
|
||||||
// Add back C: prefix on Windows
|
// Add back C: prefix on Windows
|
||||||
@ -41,23 +37,17 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption
|
|||||||
return PREFIX + resolvedId
|
return PREFIX + resolvedId
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importer && /^\.{1,2}\//.test(id)) {
|
if (importer && /^\.{1,2}[\\/]/.test(id)) {
|
||||||
const path = resolve(dirname(withoutPrefix(importer)), id)
|
const path = resolve(dirname(withoutPrefix(importer)), id)
|
||||||
const resolved = resolveWithExt(path)
|
const resolved = resolveWithExt(path)
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
return PREFIX + resolved
|
return PREFIX + resolved
|
||||||
}
|
}
|
||||||
if (importer.startsWith(PREFIX)) {
|
|
||||||
const fsPath = await findPath(path, { fallbackToOriginal: false })
|
|
||||||
if (fsPath) {
|
|
||||||
return fsPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
loadInclude (id) {
|
loadInclude (id) {
|
||||||
return id.startsWith(PREFIX)
|
return id.startsWith(PREFIX) && withoutPrefix(id) in nuxt.vfs
|
||||||
},
|
},
|
||||||
|
|
||||||
load (id) {
|
load (id) {
|
||||||
|
@ -109,7 +109,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
alias: {
|
alias: {
|
||||||
...nodeCompat.alias,
|
...nodeCompat.alias,
|
||||||
...ctx.config.resolve?.alias,
|
...ctx.config.resolve?.alias,
|
||||||
'#internal/nitro': '#build/nitro.client.mjs',
|
'#internal/nitro': join(ctx.nuxt.options.buildDir, 'nitro.client.mjs'),
|
||||||
},
|
},
|
||||||
dedupe: [
|
dedupe: [
|
||||||
'vue',
|
'vue',
|
||||||
|
Loading…
Reference in New Issue
Block a user