@@ -11,7 +11,7 @@ interface VirtualFSPluginOptions {
11
11
}
12
12
13
13
const RELATIVE_ID_RE = / ^ \. { 1 , 2 } [ \\ / ] /
14
- export const VirtualFSPlugin = ( nuxt : Nuxt , options : VirtualFSPluginOptions ) => createUnplugin ( ( ) => {
14
+ export const VirtualFSPlugin = ( nuxt : Nuxt , options : VirtualFSPluginOptions ) => createUnplugin ( ( _ , meta ) => {
15
15
const extensions = [ '' , ...nuxt . options . extensions ]
16
16
const alias = { ...nuxt . options . alias , ...options . alias }
17
17
@@ -26,31 +26,46 @@ export const VirtualFSPlugin = (nuxt: Nuxt, options: VirtualFSPluginOptions) =>
26
26
}
27
27
}
28
28
29
- return {
30
- name : 'nuxt:virtual' ,
29
+ function resolveId ( id : string , importer ?: string ) {
30
+ id = resolveAlias ( id , alias )
31
31
32
- resolveId : {
33
- order : 'pre' ,
34
- handler ( id , importer ) {
35
- id = resolveAlias ( id , alias )
32
+ if ( process . platform === 'win32' && isAbsolute ( id ) ) {
33
+ // Add back C: prefix on Windows
34
+ id = resolve ( id )
35
+ }
36
36
37
- if ( process . platform === 'win32' && isAbsolute ( id ) ) {
38
- // Add back C: prefix on Windows
39
- id = resolve ( id )
40
- }
37
+ const resolvedId = resolveWithExt ( id )
38
+ if ( resolvedId ) {
39
+ return PREFIX + encodeURIComponent ( resolvedId )
40
+ }
41
41
42
- const resolvedId = resolveWithExt ( id )
43
- if ( resolvedId ) {
44
- return PREFIX + encodeURIComponent ( resolvedId )
45
- }
42
+ if ( importer && RELATIVE_ID_RE . test ( id ) ) {
43
+ const path = resolve ( dirname ( withoutPrefix ( decodeURIComponent ( importer ) ) ) , id )
44
+ // resolve relative paths to virtual files
45
+ const resolved = resolveWithExt ( path )
46
+ if ( resolved ) {
47
+ return PREFIX + encodeURIComponent ( resolved )
48
+ }
49
+ }
50
+ }
51
+
52
+ return {
53
+ name : 'nuxt:virtual' ,
46
54
47
- if ( importer && RELATIVE_ID_RE . test ( id ) ) {
48
- const path = resolve ( dirname ( withoutPrefix ( decodeURIComponent ( importer ) ) ) , id )
49
- const resolved = resolveWithExt ( path )
50
- if ( resolved ) {
51
- return PREFIX + encodeURIComponent ( resolved )
55
+ resolveId : meta . framework === 'vite' ? undefined : { order : 'pre' , handler : resolveId } ,
56
+
57
+ vite : {
58
+ resolveId : {
59
+ order : 'pre' ,
60
+ handler ( id , importer ) {
61
+ const res = resolveId ( id , importer )
62
+ if ( res ) {
63
+ return res
52
64
}
53
- }
65
+ if ( importer && importer . startsWith ( PREFIX ) && RELATIVE_ID_RE . test ( id ) ) {
66
+ return this . resolve ?.( id , withoutPrefix ( decodeURIComponent ( importer ) ) , { skipSelf : true } )
67
+ }
68
+ } ,
54
69
} ,
55
70
} ,
56
71
0 commit comments