worker-loader
worker-loader copied to clipboard
[feat] support load plain worker module in another worker
- Operating System: macOS 12
- Node Version: 12.22.1
- NPM Version: 6.14.12
- webpack Version: 5.39.0
- worker-loader Version: 3.0.8
Feature Proposal
excludeImportee
option to exclude worker be loaded as webpack WebWorker
Feature Use Case
If 'b.worker.js' imports 'a.worker.js' to reuse some of its logic, it will just throw errors
https://github.com/JounQin/test/blob/worker-loader/src/b.worker.js
Please check https://github.com/JounQin/test/blob/worker-loader for example.
Workaround:
exclude a.worker.js
from worker-loader
, and use worker-loader!./a.worker
instead.
@JounQin Why do you use worker-loader
with webpack v5?
@alexander-akait Oh, sorry, I didn't notice the native worker support in webpack v5, but using worker-loader
seems still valid and cleaner, isn't it?
const aWorker = new Worker(new URL('./a.worker', import.meta.url))
// vs
import AWorker from './a.worker'
const aWorker = new AWorker()
@JounQin Yep, worker-loader should work, but here some limitations - cache will not work as expected and some features is not available
That's why I'm asking for this feature here, if it's not possible to support it, feel free to close, I'll continue to use my current workaround as above.
@JounQin There is solution for webpack v4 https://github.com/GoogleChromeLabs/worker-plugin, it should be better than this loader (also it will be deprecated in near future)