Any Webpack splitchunks.name as a function documentation other than from the website?

时间:2019-04-16 23:14:26

标签: webpack webpack-4 webpack-splitchunks splitchunksplugin

with the introduction of webpack 4, splitChunks.name is used to define the name of a split chunk. here, the documentation says the key can be mapped to a function for custom naming:

https://webpack.js.org/plugins/split-chunks-plugin/#splitchunksname

It takes in params module, chunks, cacheGroupKey. the documentation for these params is kind of lacking, but I can use intuition for some. ie, cacheGroupKey pertains to the keys defined in splitChunks.cacheGroups. i think chunks are the chunks that share common code that is a part of the cacheGroupKey chunk but there's no official docs about that anywhere.

so, my question is does anyone have any insights on what those three parameters are referring to?

1 个答案:

答案 0 :(得分:3)

每个参数都是webpack提供的对象,每个对象都有大量参数。这是我发现对解决此问题有用的信息:

chunks是Chunk对象的列表,每个对象具有大量的属性(对命名最有用的是chunk.namechunk.hash)。每个块都有模块,每个模块都有块,等等。SplitChunksPlugin将以优化网络性能的方式生成这些块列表,因此,除非您是高级用户,否则您不必担心什么块包含哪些块。

此函数将返回所需的块名称。因此,您可以使用JavaScript逻辑以及chunk.namechunk.hash值创建一个您希望块名称为JS字符串,并返回该字符串,该字符串将设置块名称。希望这会有所帮助!