worker-loader icon indicating copy to clipboard operation
worker-loader copied to clipboard

[feat] support load plain worker module in another worker

Open JounQin opened this issue 3 years ago • 5 comments

  • 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

image

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 avatar Jun 15 '21 03:06 JounQin

@JounQin Why do you use worker-loader with webpack v5?

alexander-akait avatar Jun 15 '21 12:06 alexander-akait

@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 avatar Jun 15 '21 12:06 JounQin

@JounQin Yep, worker-loader should work, but here some limitations - cache will not work as expected and some features is not available

alexander-akait avatar Jun 15 '21 12:06 alexander-akait

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 avatar Jun 15 '21 16:06 JounQin

@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)

alexander-akait avatar Jun 15 '21 16:06 alexander-akait