GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

[Bug?] Parent compiler's plugins are not inherited into the child compiler. #13

Closed lacolaco closed 5 years ago

lacolaco commented 5 years ago

My story is here: https://medium.com/lacolaco-blog/an-issue-around-angular-cli-comlink-workerplugin-585be1c8d087

My friend @manfredsteyer figured out the cause of the error. WorkerPlugin creates a child webpack compiler for worker module's compilation.

https://github.com/GoogleChromeLabs/worker-plugin/blob/master/src/loader.js#L42

const workerCompiler = this._compilation.createChildCompiler(NAME, workerOptions);

createChildCompiler API takes three arguments; its name, outputOptions, and plugins. The current implementation in WorkerPlugin doesn't pass the 3rd argument, so the child compiler doesn't has plugins inherited from the parent.

Solution:

Add the 3rd argument and pass compilerOptions.plugin.

const workerCompiler = this._compilation.createChildCompiler(NAME, workerOptions, compilerOptions.plugins);

In my case, it works well as I expected.

If this is by design, I'd like to know the reason.

lacolaco commented 5 years ago

@developit Could you let me know your view? Thanks.

developit commented 5 years ago

I've released this as 2.0.1 - give it a try and let me know if it works. I think we'll probably be playing whack-a-mole disabling plugins for a while though. If it causes too many issues we'll have to switch to having an option of "plugins to allow".

lacolaco commented 5 years ago

@developit Thank you! In my case, v2.0.1 works perfectly. I've confirmed no errors and no degradation.