webpack.js.org icon indicating copy to clipboard operation
webpack.js.org copied to clipboard

`splitChunks.cacheGroups.defaultVendors` not extending default behavior

Open SevenOutman opened this issue 4 years ago • 6 comments

Bug report

I was trying to split my app code and all node_modules packages into two separate bundles and I wanted to name the dependencies bundle vendors.js.

Here's my configuration:

splitChunks: {
  chunks: 'all',
  cacheGroups: {
    defaultVendors: {
      name: 'vendors',
    },
  },
},

What is the current behavior?

The output app bundle contains only runtime scaffold and vendors bundle contains both dependencies and all my app code.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

The app bundle should contain my app code and the vendors bundle contains node_modules dependencies.

FYI, adding test: /[\\/]node_modules[\\/]/ rule to defaultVendors config solves this problem. So I believe providing defaultVendors option replaced the default behavior instead of extending it.

Other relevant information: webpack version: 5.43.0 Node.js version: 14.15.5 Operating System: macOS 11.4 Additional tools:

SevenOutman avatar Jul 08 '21 15:07 SevenOutman

For maintainers only:

  • [ ] webpack-4
  • [ ] webpack-5
  • [ ] bug
  • [ ] critical-bug
  • [ ] enhancement
  • [ ] documentation
  • [ ] performance
  • [ ] dependencies
  • [ ] question

webpack-bot avatar Jul 08 '21 15:07 webpack-bot

Yes, using splitChunks.cacheGroups.defaultVendors is not extending default behavior, it is expected (https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L1030), we need docs it, feel free to feedback

alexander-akait avatar Jul 12 '21 10:07 alexander-akait

Yes, using splitChunks.cacheGroups.defaultVendors is not extending default behavior, it is expected

I see. But why should it not be extending default behavior? It's not so straightforward from my point of view. You always need to search for the complete default config when you only need to overwrite one attribute in it.

SevenOutman avatar Jul 12 '21 10:07 SevenOutman

Because it was implemented, if we extend other developers ask why we extend, and we decided do not extend, like it happens in JS, when you change property of object, in webpack we have ... syntax for merging/extending, but here blocker https://github.com/webpack/webpack/pull/13726/ for objects

alexander-akait avatar Jul 12 '21 11:07 alexander-akait

Thanks for your explanation! Keeping an eye on the PR now.

SevenOutman avatar Jul 12 '21 11:07 SevenOutman

Let's keep open here, we need improve our docs

alexander-akait avatar Jul 12 '21 12:07 alexander-akait