@@ -46,10 +46,16 @@ exports.resolve = (source, file, config) => {
46
46
}
47
47
48
48
const defaultExtensions = [ ".mjs" , ".js" , ".ts" , ".jsx" , ".tsx" , ".json" ] ;
49
- const { alias, extensions } = viteConfig . resolve ?? { } ;
49
+ const { alias, extensions = defaultExtensions } = viteConfig . resolve ?? { } ;
50
50
51
51
let actualSource = source ;
52
52
53
+ // public dir
54
+ const publicDir = viteConfig . publicDir || "public" ;
55
+ if ( actualSource . charAt ( 0 ) === "/" && ! fs . existsSync ( actualSource ) ) {
56
+ actualSource = path . join ( path . resolve ( publicDir ) , actualSource ) ;
57
+ }
58
+
53
59
// parse and replace alias
54
60
if ( alias ) {
55
61
Object . entries ( alias ) . forEach ( ( [ find , replacement ] ) => {
@@ -59,9 +65,10 @@ exports.resolve = (source, file, config) => {
59
65
60
66
// resolve module
61
67
const resolvedPath = resolve . sync ( actualSource , {
62
- basedir : path . dirname ( path . resolve ( file ) ) ,
63
- extensions : extensions ?? defaultExtensions ,
68
+ basedir : path . dirname ( file ) ,
69
+ extensions,
64
70
} ) ;
71
+
65
72
log ( "resolved to:" , resolvedPath ) ;
66
73
return { found : true , path : resolvedPath } ;
67
74
}
0 commit comments