What does optimization.splitChunks configuration commons and vendor mean in webpack?

recently, in the process of learning webpack4, I encountered a problem, that is, it is said on the official website of optimization.splitChunks, that it is used for subcontracting. Pack the repeatedly introduced modules into a js to prevent repeated packaging. I can understand this, but I do not quite understand the specific configuration. Ask God for advice, the following is the code:

optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    name: "commons",
                    chunks: "initial",
                    minChunks: 2
                },
                vendor: { 
                    chunks: "all",
                    test: /[\\/]node_modules[\\/]/,
                    name: "vendor",
                    minChunks: 1,
                    maxInitialRequests: 5,
                    minSize: 0,
                    priority: 100
                }
            }
        }
    }

this is my own configuration, and then I did not pack out 2 js, as I thought. I would like to ask, what are the meanings of commons and vendor, under what circumstances are they used, and what is the meaning of each configuration? I wrote this, why only a js (vendor), commons is packaged? if name is not set, then what is the file name generated? and, I found that the packaged vendor.js is very large, is it normal?
I would like to ask the Great God for his advice, thank you very much!

Apr.30,2021

commons is generally defined by an individual, vendor is an imported npm package (as can be seen in test), the module used for personal definition by
commons is referenced repeatedly, the package introduced by vendor for npm is referenced repeatedly, and the configuration of
is not mentioned.
packages only one js because commons lacks a configuration item minSize: 0. This item must have, because the default value of webpack is 30k, it is obvious that my packaged commons is less than 30k, so I must specify its minimum volume.
if the file name produced by name, is the introduced bundle plus the automatic naming connector (automaticNameDelimiter:'~'),
because vendor is an imported npm package merge file, it is normal, but because it is almost unchanged, it can be handed over to the client cache


. Generally speaking,
commons is your handwritten
vendor is the imported npm package
. This may be because chunks: "all" covers the above
package. It is no problem because vendor is cached on the client side, and the traffic consumption is more when it is loaded for the first time

.

refer to https://webpack.js.org/plugin.

Menu