@@ -9,7 +9,7 @@ import type { Plugin } from '../plugin'
99import { evalValue , injectQuery , transformStableResult } from '../utils'
1010import { createBackCompatIdResolver } from '../idResolver'
1111import type { ResolveIdFn } from '../idResolver'
12- import { cleanUrl , slash } from '../../shared/utils'
12+ import { cleanUrl , slash , splitFileAndPostfix } from '../../shared/utils'
1313import type { WorkerType } from './worker'
1414import {
1515 WORKER_FILE_ID ,
@@ -234,21 +234,23 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
234234 s ||= new MagicString ( code )
235235 const workerType = await getWorkerType ( code , cleanString , endIndex )
236236 const url = rawUrl . slice ( 1 , - 1 )
237+ const { file : urlWithoutPostfix , postfix } = splitFileAndPostfix ( url )
238+ const queryPostfix = postfix [ 0 ] === '?' ? postfix : ''
237239 let file : string | undefined
238- if ( url [ 0 ] === '.' ) {
239- file = path . resolve ( path . dirname ( id ) , url )
240+ if ( urlWithoutPostfix [ 0 ] === '.' ) {
241+ file = path . resolve ( path . dirname ( id ) , urlWithoutPostfix )
240242 file = slash ( tryFsResolve ( file , fsResolveOptions ) ?? file )
241243 } else {
242244 workerResolver ??= createBackCompatIdResolver ( config , {
243245 extensions : [ ] ,
244246 tryIndex : false ,
245247 preferRelative : true ,
246248 } )
247- file = await workerResolver ( this . environment , url , id )
249+ file = await workerResolver ( this . environment , urlWithoutPostfix , id )
248250 file ??=
249- url [ 0 ] === '/'
250- ? slash ( path . join ( config . publicDir , url ) )
251- : slash ( path . resolve ( path . dirname ( id ) , url ) )
251+ urlWithoutPostfix [ 0 ] === '/'
252+ ? slash ( path . join ( config . publicDir , urlWithoutPostfix ) )
253+ : slash ( path . resolve ( path . dirname ( id ) , urlWithoutPostfix ) )
252254 }
253255
254256 if (
@@ -282,7 +284,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
282284 } else {
283285 builtUrl = await fileToUrl ( this , cleanUrl ( file ) )
284286 builtUrl = injectQuery (
285- builtUrl ,
287+ ` ${ builtUrl } ${ queryPostfix } ` ,
286288 `${ WORKER_FILE_ID } &type=${ workerType } ` ,
287289 )
288290 }
0 commit comments