- https://juejin.cn/post/6844904150988226574
splitChunks
const path = require('path')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
productionSourceMap: false,
lintOnSave: false,
devServer: {
port: '8080',
open: true,
hot: true,
disableHostCheck: true,
clientLogLevel: 'warning',
overlay: {
warnings: false,
errors: true
}
},
configureWebpack: {
devtool: 'source-map',
name: 'dfdf',
resolve: {
alias: {
'@': resolve('src')
}
},
plugins: [
]
},
chainWebpack: config => {
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
html2canvas: {
name: 'chunk-html2canvas',
test: /[/]node_modules[/]_?html2canvas(.*)/,
priority: 10
},
swiper: {
name: 'chunk-swiper',
test: /[/]node_modules[/]_?swiper(.*)/,
priority: 10
},
vant: {
name: 'chunk-vant',
priority: 20,
test: /[/]node_modules[/]_?vant(.*)/
},
commons: {
name: 'chunk-commons',
minChunks: 2,
priority: 5,
chunks: 'initial',
reuseExistingChunk: true
},
corejs: {
name: 'chunk-corejs',
test: /[/]node_modules[/]_?core-js(.*)/,
priority: 10
}
}
})
config.module
.rule('svgIcon')
.test(/\.svg$/)
.include
.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.tap(options => {
options = {
symbolId: 'icon-[name]'
}
return options
})
config.module
.rule('svg')
.exclude
.add(resolve('src/icons'))
.end()
config
.plugin('html')
.tap(args => {
args[0].title = '珍客企微版'
return args
})
}
}