Skip to content

Commit d464679

Browse files
authoredMar 12, 2023
fix(worker): force rollup to build worker module under watch mode (#11919)
1 parent 21ffc6a commit d464679

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed
 

‎packages/vite/src/node/plugins/worker.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
198198
let server: ViteDevServer
199199
const isWorker = config.isWorker
200200

201+
const isWorkerQueryId = (id: string) => {
202+
const parsedQuery = parseRequest(id)
203+
if (
204+
parsedQuery &&
205+
(parsedQuery.worker ?? parsedQuery.sharedworker) != null
206+
) {
207+
return true
208+
}
209+
210+
return false
211+
}
212+
201213
return {
202214
name: 'vite:worker',
203215

@@ -217,15 +229,16 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
217229
},
218230

219231
load(id) {
220-
if (isBuild) {
221-
const parsedQuery = parseRequest(id)
222-
if (
223-
parsedQuery &&
224-
(parsedQuery.worker ?? parsedQuery.sharedworker) != null
225-
) {
226-
return ''
227-
}
232+
if (isBuild && isWorkerQueryId(id)) {
233+
return ''
234+
}
235+
},
236+
237+
shouldTransformCachedModule({ id }) {
238+
if (isBuild && isWorkerQueryId(id) && config.build.watch) {
239+
return true
228240
}
241+
return false
229242
},
230243

231244
async transform(raw, id, options) {

0 commit comments

Comments
 (0)
Please sign in to comment.