问题描述
随着 webpack 4 的引入,splitChunks.name
用于定义拆分块的名称.在这里,文档说可以将键映射到自定义命名的函数:
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-块插件/#splitchunksname
它接受参数module
、chunks
、cacheGroupKey
.这些参数的文档有点缺乏,但我可以使用一些直觉.即,cacheGroupKey
属于splitChunks.cacheGroups
中定义的键.我认为 chunks
是共享公共代码的块,它是 cacheGroupKey
块的一部分,但在任何地方都没有关于它的官方文档.
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?
推荐答案
每个参数都是 webpack 提供的一个对象,每个参数都有一吨的参数.以下是我发现对解决此问题有用的信息:
Each parameter is an object provided by webpack, each with a ton of parameters. Here's what information I found useful in facing this problem:
chunks
是一个 Chunk 对象的列表,每个对象都有大量的属性(最有用的命名是 chunk.name
和 chunk.hash代码>).每个块都有模块,每个模块都有块等. SplitChunksPlugin 会以优化 Web 性能的方式生成这些块列表,因此除非您是高级用户,否则您不必担心哪些块与哪些块.
chunks
is a list of Chunk objects, each having a ton of properties (the most useful for naming being chunk.name
and chunk.hash
). Each chunk has modules, each module has chunks, etc. SplitChunksPlugin will generate these lists of chunks in a way that will optimize web performance, so unless you're an advanced user you won't have to worry about what chunks are with what chunks.
此函数将返回块的所需名称.因此,您可以使用 JavaScript 逻辑和 chunk.name
和 chunk.hash
值来创建一个您希望块名称为的 JS 字符串,并返回该字符串,这将设置块名称.希望这会有所帮助!
This function will return the desired name of the chunk. So, you can use JavaScript logic and the chunk.name
and chunk.hash
values to create a JS string that you want your the chunk name to be, and return that string, which will set the chunk name. Hope this helps!
这篇关于任何 Webpack splitchunks.name 作为功能文档而不是来自网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!