其他分享
首页 > 其他分享> > 打包js库防止重复 shared与 SplitChunksPlugin

打包js库防止重复 shared与 SplitChunksPlugin

作者:互联网

module.exports = {
entry: {
index: {
import: './src/index.js',
dependOn: 'shared',
},
another: {
import: './src/another-module.js',
dependOn: 'shared',
},
shared: 'lodash',
}
}
//...
module.exports = {
entry: {
index: {
import: './src/index.js',
dependOn: 'shared',
},
another: {
import: './src/another-module.js',
dependOn: 'shared',
},
shared: 'lodash', //抽离出共同的lodash库
},
//...

splitChunksPlugin 插件可以将公共的依赖模块提取到已有的入口 chunk 中,或者提取到一个新生成的 chunk。让我们使用这个插件,将之前的示例中重 复的 lodash 模块去除

entry: {
index: './src/index.js',
another: './src/another-module.js'
},
optimization: {
splitChunks: {
chunks: 'all',
},
},

 

标签:src,SplitChunksPlugin,index,module,js,another,shared
来源: https://www.cnblogs.com/yyy1234/p/16221954.html