@@ -25,7 +25,7 @@ import {
2525} from '../build'
2626import { cleanUrl } from '../../shared/utils'
2727import type { Logger } from '../logger'
28- import { fileToUrl } from './asset'
28+ import { fileToUrl , toOutputFilePathInJSForBundledDev } from './asset'
2929
3030type WorkerBundle = {
3131 entryFilename : string
@@ -401,7 +401,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
401401 const { format } = config . worker
402402 const workerConstructor =
403403 workerMatch [ 1 ] === 'sharedworker' ? 'SharedWorker' : 'Worker'
404- const workerType = isBuild
404+ const workerType = config . isBundled
405405 ? format === 'es'
406406 ? 'module'
407407 : 'classic'
@@ -412,7 +412,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
412412 }`
413413
414414 let urlCode : string
415- if ( isBuild ) {
415+ if ( config . isBundled ) {
416416 if ( isWorker && config . bundleChain . at ( - 1 ) === cleanUrl ( id ) ) {
417417 urlCode = 'self.location.href'
418418 } else if ( inlineRE . test ( id ) ) {
@@ -467,7 +467,19 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
467467 }
468468 } else {
469469 const result = await workerFileToUrl ( config , id )
470- urlCode = JSON . stringify ( result . entryUrlPlaceholder )
470+ let url : string
471+ if (
472+ this . environment . config . command === 'serve' &&
473+ this . environment . config . experimental . bundledDev
474+ ) {
475+ url = toOutputFilePathInJSForBundledDev (
476+ this . environment ,
477+ result . entryFilename ,
478+ )
479+ } else {
480+ url = result . entryUrlPlaceholder
481+ }
482+ urlCode = JSON . stringify ( url )
471483 for ( const file of result . watchedFiles ) {
472484 this . addWatchFile ( file )
473485 }
@@ -517,7 +529,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
517529 const scriptPath = JSON . stringify ( ENV_PUBLIC_PATH )
518530 injectEnv = `import ${ scriptPath } \n`
519531 } else if ( workerType === 'ignore' ) {
520- if ( isBuild ) {
532+ if ( config . isBundled ) {
521533 injectEnv = ''
522534 } else {
523535 // dynamic worker type we can't know how import the env
0 commit comments