File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed
Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1076,6 +1076,12 @@ const relativeUrlMechanisms: Record<
10761076}
10771077/* end of copy */
10781078
1079+ const customRelativeUrlMechanisms = {
1080+ ...relativeUrlMechanisms ,
1081+ 'worker-iife' : ( relativePath ) =>
1082+ getResolveUrl ( `'${ relativePath } ', self.location.href` ) ,
1083+ } as const satisfies Record < string , ( relativePath : string ) => string >
1084+
10791085export type RenderBuiltAssetUrl = (
10801086 filename : string ,
10811087 type : {
@@ -1125,8 +1131,10 @@ export function toOutputFilePathInJS(
11251131
11261132export function createToImportMetaURLBasedRelativeRuntime (
11271133 format : InternalModuleFormat ,
1134+ isWorker : boolean ,
11281135) : ( filename : string , importer : string ) => { runtime : string } {
1129- const toRelativePath = relativeUrlMechanisms [ format ]
1136+ const formatLong = isWorker && format === 'iife' ? 'worker-iife' : format
1137+ const toRelativePath = customRelativeUrlMechanisms [ formatLong ]
11301138 return ( filename , importer ) => ( {
11311139 runtime : toRelativePath (
11321140 path . posix . relative ( path . dirname ( importer ) , filename ) ,
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ export function renderAssetUrlInJS(
6969) : MagicString | undefined {
7070 const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime (
7171 opts . format ,
72+ config . isWorker ,
7273 )
7374
7475 let match : RegExpExecArray | null
Original file line number Diff line number Diff line change @@ -355,6 +355,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
355355 if ( code . match ( workerAssetUrlRE ) || code . includes ( 'import.meta.url' ) ) {
356356 const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime (
357357 outputOptions . format ,
358+ config . isWorker ,
358359 )
359360
360361 let match : RegExpExecArray | null
You can’t perform that action at this time.
0 commit comments