mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix: resolve fs paths relative to build directory
This commit is contained in:
parent
1299e858df
commit
1795ae0ddb
@ -1,5 +1,5 @@
|
|||||||
import { resolveAlias, useNuxt } from '@nuxt/kit'
|
import { findPath, resolveAlias, useNuxt } from '@nuxt/kit'
|
||||||
import { dirname, isAbsolute, join, resolve } from 'pathe'
|
import { dirname, isAbsolute, resolve } from 'pathe'
|
||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
|
|
||||||
const PREFIX = '\0virtual:nuxt:'
|
const PREFIX = '\0virtual:nuxt:'
|
||||||
@ -27,7 +27,7 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption
|
|||||||
return {
|
return {
|
||||||
name: 'nuxt:virtual',
|
name: 'nuxt:virtual',
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
resolveId (id, importer) {
|
async resolveId (id, importer) {
|
||||||
const _id = id
|
const _id = id
|
||||||
id = resolveAlias(id, alias)
|
id = resolveAlias(id, alias)
|
||||||
|
|
||||||
@ -41,14 +41,18 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption
|
|||||||
return PREFIX + resolvedId
|
return PREFIX + resolvedId
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importer && !isAbsolute(id)) {
|
if (importer && /^\.{1,2}\//.test(id)) {
|
||||||
if (importer.startsWith(PREFIX)) {
|
const path = resolve(dirname(withoutPrefix(importer)), id)
|
||||||
importer = importer.slice(PREFIX.length)
|
const resolved = resolveWithExt(path)
|
||||||
}
|
|
||||||
const resolved = resolveWithExt(join(dirname(importer), id))
|
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -58,9 +62,13 @@ export const VirtualFSPlugin = (nuxt = useNuxt(), options: VirtualFSPluginOption
|
|||||||
|
|
||||||
load (id) {
|
load (id) {
|
||||||
return {
|
return {
|
||||||
code: nuxt.vfs[id.slice(PREFIX.length)] || '',
|
code: nuxt.vfs[withoutPrefix(id)] || '',
|
||||||
map: null,
|
map: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function withoutPrefix (id: string) {
|
||||||
|
return id.startsWith(PREFIX) ? id.slice(PREFIX.length) : id
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user