compression-webpack-plugin
npm i compression-webpack-plugin
Vue 配置文件
分片打包
const CompressionPlugin = require("compression-webpack-plugin");
chainWebpack: (config) => {
config.resolve.alias
.set("@$", resolve("src"))
.set("@api", resolve("src/api"))
.set("@assets", resolve("src/assets"))
.set("@comp", resolve("src/components"))
.set("@views", resolve("src/views"));
if (process.env.NODE_ENV === "production") {
config.plugin("compressionPlugin").use(
new CompressionPlugin({
test: /\.(js|css|less)$/,
threshold: 10240,
deleteOriginalAssets: false,
})
);
}
};
分依赖模块打包
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.optimization.runtimeChunk = 'single'
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
config.optimization.splitChunks = {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 2000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
return `npm.${packageName.replace('@', '')}`
}
}
}
};
}
},