Skip to content

Commit

Permalink
fix(worker): force rollup to build worker module under watch mode (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Mar 12, 2023
1 parent 21ffc6a commit d464679
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand All @@ -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) {
Expand Down

0 comments on commit d464679

Please sign in to comment.