Skip to content

Commit

Permalink
feat: extract worker name
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 29, 2023
1 parent 6d99042 commit cb094b9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vite-plugin-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export default function SharedWorker(options?: { root?: string }): Plugin {
const exports = findExports(code).filter((ex) => !!ex.name);

if (isClient) {
const workerName = path.basename(id.split('?')[0]);
return [
`// vite-plugin-sharedworker starts`,
`import { defineClient } from 'vite-plugin-sharedworker/runtime'`,
`const worker = new SharedWorker(new URL(${JSON.stringify(
id
)}, import.meta.url), { type: 'module', name: 'worker' });`,
)}, import.meta.url), { type: 'module', name: ${JSON.stringify(workerName)} });`,
`const client = defineClient(worker)`,
`// vite-plugin-sharedworker ends`,
...exports.map(
Expand Down

0 comments on commit cb094b9

Please sign in to comment.