From d464679bf7407376c56ddf5b6174e91e1a74a2b5 Mon Sep 17 00:00:00 2001 From: Wei Date: Sun, 12 Mar 2023 22:49:53 +0800 Subject: [PATCH] fix(worker): force rollup to build worker module under watch mode (#11919) --- packages/vite/src/node/plugins/worker.ts | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index d9f719b352437a..aae1a4a1423cda 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -198,6 +198,18 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin { let server: ViteDevServer const isWorker = config.isWorker + const isWorkerQueryId = (id: string) => { + const parsedQuery = parseRequest(id) + if ( + parsedQuery && + (parsedQuery.worker ?? parsedQuery.sharedworker) != null + ) { + return true + } + + return false + } + return { name: 'vite:worker', @@ -217,15 +229,16 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin { }, load(id) { - if (isBuild) { - const parsedQuery = parseRequest(id) - if ( - parsedQuery && - (parsedQuery.worker ?? parsedQuery.sharedworker) != null - ) { - return '' - } + if (isBuild && isWorkerQueryId(id)) { + return '' + } + }, + + shouldTransformCachedModule({ id }) { + if (isBuild && isWorkerQueryId(id) && config.build.watch) { + return true } + return false }, async transform(raw, id, options) {