CommonsChunkPlugin好像只会将所有chunk中都共有的模块抽取出来,如果存在如下的依赖
// entry1.js
var style1 = require('./style/myStyle.css')
var style2 = require('./style/style.css')
// entry2.js
require("./style/myStyle.css")
require("./style/myStyle2.css")
// entry3.js
require("./style/myStyle2.css")
使用插件后会发现,根本没有生成commons.css文件。
如果我们只需要取前两个chunk的共同代码,我们可以这么做
module.exports = {
entry: {
"A": "./src/entry.js",
"B": "./src/entry2.js",
"C": "./src/entry3.js"
},
...
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "commons", filename: "commons.js", chunks: ['A', 'B']
}),
...
]
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持黑区网络。

