developit / developit/workerize-loader

Can't apply plugins to worker

Đang mở
#87 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
2.3k
Fork
85
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Currently there is no way to pass plugins to workerize-loader.

Webpack's documentation is _wrong_ when it states that child compilers inherit all hooks and plugins from the parent compiler. They infact do _not_ inherit plugins at all; they _copy over_ a number of hooks from the parent compiler -- where some plugins may have added them -- to the child compiler.

Several hooks are blacklisted. Banned from this copy process are: `make`, `compile`, `emit`, `afterEmit`, `invalid`, `done`, and `thisCompilation`. There are ofcourse good reasons not to copy those hooks - as doing so would mess with the control flow for the child compilation and parent compilation. However, it does mean the child compiler has to be fed its own instances of plugins such as the `CompressionPlugin` which attach to those hooks.

https://github.com/webpack/webpack/blob/498bb0841bd79476569701dc2e4f0f65dc87359c/lib/Compiler.js#L773-L846

This is what the third `plugins` argument to the `createChildCompiler` method is for, but having a look at how the child compiler that creates the body of the worker is called:

https://github.com/developit/workerize-loader/blob/2688667adf334e45c69c04ee3bd60f68a455583a/src/index.js#L59

it doesn't link up that third parameter. So right now there is no well-defined way to e.g. apply `CompressionPlugin` and get Gzip or Brotli compressed workers.

-----

It may still be possible to achieve this by tapping the `childCompiler` hook on the parent compilation, as it does get passed the created child compiler.

This requires people write their *own* custom "plugin to apply plugins" - which is well beyond the comfort zone of most Webpack users. (Most webpack users don't write their own plugins. That's something you typically only do if you really; _really_ know what you're doing. )

It's also not exactly trivial to get right, as you'd still also need to _filter by the child compiler's name_ to ensure they're only adding plugins to the correct child compilers created by the workerize-loader and not to e.g. those created by the MiniCssExtractPlugin. Making this worse is the fact that those child compiler names are internal implementation details and not part of any public API, i.e. are subject to change over time.

I.e. this is a short-term workaround at best.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Start in src/index.js around the createChildCompiler call at line 59 and review webpack's Compiler.js child-compiler behavior at the linked lines. Trace how worker child compilers are created and determine how a plugin list could be supplied without affecting unrelated child compilers. Done means worker builds can receive plugins such as CompressionPlugin, with coverage for the supported configuration.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, webpack
Lĩnh vực
build-system, tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.