Skip to content

[Feature]: Support web-worker #929

Description

@SoonIter

What problem does this feature solve?

the bundleless workaround

defineConfig({
lib: [{
  bundle: false,
  format: 'esm',
      syntax: 'esnext',
      tools: {
        rspack: {
          module: {
            parser: {
              javascript: {
                worker: false,
              },
            },
          },
        },
      },
}]
})

but in bundle mode

there are tons of webpack runtime

Image

What does the proposed API look like?

test demo: https://github.com/SoonIter/rslib-worker-demo

Input

index.ts
fib-worker.ts
chat-worker.ts
utils.ts
// ...
const chatWorker = new SharedWorker(new URL('./chat-worker.ts', import.meta.url), {
    name: 'chat',
    type: 'module'
});
// ...
const fibWorker = new Worker(new URL('./fib-worker.ts', import.meta.url), {
    name: 'fibonacci',
    type: 'module'
});

Expected ouput

in bundle the output should be:

index.js
fib-worker.js
chat-worker.js
// ...
const chatWorker = new SharedWorker(new URL('./chat-worker.js', import.meta.url), {
    name: 'chat',
    type: 'module'
});
// ...
const fibWorker = new Worker(new URL('./fib-worker.js', import.meta.url), {
    name: 'fibonacci',
    type: 'module'
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions