Files
gzh/vue.config.js
2026-01-06 15:03:14 +08:00

96 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 优化配置:结合压缩和代码拆分,提高页面访问速度
const path = require("path");
const CompressionPlugin = require('compression-webpack-plugin');
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = {
// lintOnSave: false,
lintOnSave: true,
parallel: true, // 启用并行编译
productionSourceMap: false, // 禁用生产环境 source map减少构建体积提高页面加载速度
// 合并配置gzip压缩 + 代码拆分
configureWebpack: {
// 只在开发环境使用source map生产环境不使用
devtool: process.env.NODE_ENV === 'development' ? 'eval-cheap-module-source-map' : false,
plugins: [
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css|html)$/,
threshold: 10240,
minRatio: 0.8
})
],
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
// 拆分 echarts 库
echarts: {
name: 'chunk-echarts',
test: /[\\/]node_modules[\\/]echarts[\\/]/,
priority: 20,
chunks: 'all'
},
// 其他第三方库
// 拆分 quill 富文本编辑器
quill: {
name: 'chunk-quill',
test: /[\\/]node_modules[\\/]quill[\\/]/,
priority: 20,
chunks: 'all'
},
// 拆分 pdf 相关库
pdf: {
name: 'chunk-pdf',
test: /[\\/]node_modules[\\/](pdfh5|vue-pdf)[\\/]/,
priority: 20,
chunks: 'all'
},
// 拆分 高德地图
amap: {
name: 'chunk-amap',
test: /[\\/]node_modules[\\/]vue-amap[\\/]/,
priority: 20,
chunks: 'all'
},
// 拆分 canvas 相关库
canvas: {
name: 'chunk-canvas',
test: /[\\/]node_modules[\\/](canvas|dommatrix)[\\/]/,
priority: 20,
chunks: 'all'
},
// 拆分 微信 SDK
weixin: {
name: 'chunk-weixin',
test: /[\\/]node_modules[\\/]weixin-js-sdk[\\/]/,
priority: 20,
chunks: 'all'
},
// 其他第三方库
vendors: {
name: 'chunk-vendors',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial'
}
}
}
}
},
chainWebpack: (config) => {
config.resolve.alias
.set("@$", resolve("src"))
.set("assets", resolve("src/assets"))
.set("components", resolve("src/components"))
.set("layout", resolve("src/layout"))
.set("base", resolve("src/base"))
.set("static", resolve("src/static"));
},
publicPath: "./",
};