webpack code splitting
一、代码分割优化
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 注入html
const CleanWebpackPlugin = require('clean-webpack-plugin');
const merge = require('webpack-merge');
const webpackBaseConf = require('./webpack.base.conf');
const webpackProConf = {
mode: 'production',
devtool: 'source-map',
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
minSize: 30000,
minChunks: 1,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
},
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
new CleanWebpackPlugin(),
new webpack.HashedModuleIdsPlugin(), // 缓存
]
};
const webpackConfigs = merge(webpackBaseConf,webpackProConf);
module.exports= webpackConfigs;
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
更多精彩

