Why is dependency repeated many times in Webpack artifact?
It sounds like you want to consolidate a dependency from multiple chunks into a common chunk: For this I would recommend looking into webpack.CommonsChunkPlugin
.
Of particular interest is the minChunks
property you can pass to the plugin:
minChunks: number|Infinity|function(module, count) -> boolean, // The minimum number of chunks which need to contain a module before it's moved into the commons chunk. // The number must be greater than or equal 2 and lower than or equal to the number of chunks. // Passing
Infinity
just creates the commons chunk, but moves no modules into it. // By providing afunction
you can add custom logic. (Defaults to the number of chunks)
I advise trying to add this plugin to your Webpack config:
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true,
minChunks: 3
})
This usage is described further in "Extra async commons chunk".
If you are interested in seeing the amount of code shared between your chunks, consider trying samccone/bundle-buddy
for Webpack as well.
If you are already using CommonsChunkPlugin
, I would need to see your Webpack config to provide further information.