codymikol / karma-webpack

Karma webpack Middleware
MIT License
829 stars 222 forks source link

Fix empty chunks with webpack v5 #456

Closed marvinhagemeister closed 3 years ago

marvinhagemeister commented 3 years ago

This PR contains a:

Motivation / Use-Case

Just tried to upgrade our karma setup over at https://github.com/preactjs/preact to webpack v5 and ran into the issue that all chunks contained no user code. They only contained a thin module wrapper by webpack.

(self["webpackChunkpreact"] = self["webpackChunkpreact"] || []).push([["Children.test.159184821"],{},
0,[["./compat/test/browser/Children.test.js","runtime","commons"]]]);

Some digging revealed that the optimize.splitChunks settings are to blame. The webpack v4 to v5 upgrade guide hints that setting it is not necessary anymore. When I follow that advice and remove them, the chunks work as expected.

Breaking Changes

Additional Info

codymikol commented 3 years ago

Hey @marvinhagemeister could you confirm that in your karma configuration that you have 'webpack' included as a framework? This is usually the culprit when no tests are found by the runner at this time.

Looking at the upgrade guide it says that chunks: 'all' is still a recommendation.

It's recommended to use either the defaults or optimization.splitChunks: { chunks: 'all' }.

marvinhagemeister commented 3 years ago

@codymikol That's interesting, I didn't know that. Iirc we didn't have it on the Frameworks so it's likely the cause of the problem 👍

We've replaced webpack with esbuild in the past weeks. So it doesn't make sense for me to spend more time investigating this I'm afraid.