Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

[feat] support load plain worker module in another worker #320

Open
JounQin opened this issue Jun 15, 2021 · 5 comments
Open

[feat] support load plain worker module in another worker #320

JounQin opened this issue Jun 15, 2021 · 5 comments

Comments

@JounQin
Copy link

JounQin commented Jun 15, 2021

  • 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 added a commit to JounQin/test that referenced this issue Jun 15, 2021
@alexander-akait
Copy link
Member

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

@JounQin
Copy link
Author

JounQin commented Jun 15, 2021

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

@alexander-akait
Copy link
Member

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

@JounQin
Copy link
Author

JounQin commented Jun 15, 2021

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.

@alexander-akait
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants