CommonsChunkPlugin 配置中 "children" 指的是什么

What does "children" refer to in CommonsChunkPlugin config

我正在努力思考 webpack 的 CommonsChunkPlugin 的配置选项。这些选项包括布尔值 children 属性。你能解释一下当它设置为 true 时会发生什么,而当它设置为 false 时会发生什么? This documentation 说 "If true all children of the commons chunk are selected," 但页面从未定义 "children of the commons chunk." children 是包含公共块的块吗?或者公共块包含的模块?此外,"selecting" 和 children 的含义是什么?

我认为这里的措辞有点误导。如果你看看相关的 example on the same documentation page 就更清楚了。

一旦开始使用代码拆分,术语块可以参考

  • 您的入口块,其子块由您代码中的拆分点创建,
  • 由您的分割点创建的区块(即您的入口区块的子区块),或
  • 您使用 CommonsChunkPlugin 合并到的公共块。

现在,正如您在文档中看到的那样,您使用 CommonsChunkPlugin 将代码合并到的公共块可以是新的公共块或现有块。后者是通过在 CommonsChunkPlugin 选项中将现有块的名称指定为公共块的 "name" 属性 来实现的。然而,根据我的经验,您只能指定作为应用程序入口点的现有块。例如,如果您的应用程序入口点的名称为 "app",则以下 CommonsChunkPlugin 选项应将 "app" 的子项中的公共代码合并到 "app" 块中。

new webpack.optimize.CommonsChunkPlugin({
  name: 'app',
  children: true
})

相反,如果您想为 "app" 的子项的公共代码创建一个新的公共块,您可以使用以下代码:

new webpack.optimize.CommonsChunkPlugin({
  name: 'app',
  filename: 'common-code.js',
  children: true,
  async: true
})

回到你引用文档的地方

If true all children of the commons chunk are selected

单词 "commons chunk" 可能应该替换为 "entry chunk"。