如何合并不同的节点模块并从中制作不同的包?

How to merge different node modules and make different bundles from them?

描述:假设我有 7 个依赖项,如下所示

"dependencies": {
  "control-module-one": "1.00",
  "control-module-two": "1.00",
  "control-module-three": "1.00",
  "react": "16.9.0",
  "react-dom": "16.9.0",
  "utility-module-one": "2.00",
  "utility-module-two": "2.00"
}

挑战: 我想以明智的方式合并模块,并使不同的捆绑包明智地分组。所以它可能像下面

dist>
  control-module-bundle.js
  react-module-bundle.js
  utility-module-bundle.js

我尝试了什么?

我在 webpack 中尝试了“splitChunks”和“cacheGroups”,但它会将所有模块捆绑在不同的文件中。

查询:可以吗?

使用 Webpack-4 的 'splitChunks' 完成。

splitChunks: {
 cacheGroups: {
  control_module_group: {
   test: /[\/]node-modules[\/]control/,
   name: 'control-module-bundle',
   chunks: 'all'
  }
 }
}