File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
packages/taro-vite-runner/src Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ export default async function (viteCompilerContext: ViteHarmonyCompilerContext):
133
133
outputRoot,
134
134
targetRoot : path . resolve ( appPath , sourceRoot ) ,
135
135
resolve : this . resolve ,
136
+ modifyResolveId : viteCompilerContext . loaderMeta . modifyResolveId ,
136
137
} )
137
138
138
139
return {
Original file line number Diff line number Diff line change @@ -297,12 +297,23 @@ export function resolveAbsoluteRequire ({
297
297
} )
298
298
}
299
299
300
+ let lastCommonPath = ''
300
301
function getCommonPath ( a : string , b : string ) {
301
302
const aArr = path . normalize ( a ) . split ( / [ \\ / ] / )
302
303
const bArr = path . normalize ( b ) . split ( / [ \\ / ] / )
303
304
let i = 0
304
305
while ( aArr [ i ] === bArr [ i ] ) {
305
306
i ++
306
307
}
307
- return aArr . slice ( 0 , i ) . join ( '/' )
308
+
309
+ if ( aArr . length > i ) {
310
+ // Note: 项目外部文件,仅返回所有外部文件的最短公共路径
311
+ if ( ! lastCommonPath || lastCommonPath . split ( / [ \\ / ] / ) . length > i ) {
312
+ lastCommonPath = aArr . slice ( 0 , i ) . join ( '/' )
313
+ }
314
+ return lastCommonPath
315
+ } else {
316
+ // Note: 项目内部文件,返回项目根路径
317
+ return a
318
+ }
308
319
}
You can’t perform that action at this time.
0 commit comments