const path = require('path');
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
const resolve = (dir) = >path.join(__dirname, dir);
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '/site/vue-demo/': '/',
indexPath: 'index.html',
outputDir: process.env.outputDir || 'dist',
assetsDir: 'static',
lintOnSave: false,
runtimeCompiler: true,
productionSourceMap: !IS_PROD,
parallel: require("os").cpus().length > 1,
pwa: {},
chainWebpack: config = >{
config.resolve.symlinks(true);
config.plugin("html").tap(args = >{
args[0].chunksSortMode = "none";
return args;
});
config.resolve.alias
.set('@', resolve('src')).set('@assets', resolve('src/assets')).set('@components', resolve('src/components')).set('@views', resolve('src/views')).set('@store', resolve('src/store'));
config.module.rule("images").use("image-webpack-loader").loader("image-webpack-loader").options({
mozjpeg: {
progressive: true,
quality: 65
},
optipng: {
enabled: false
},
pngquant: {
quality: [0.65, 0.9],
speed: 4
},
gifsicle: {
interlaced: false
},
webp: {
quality: 75
}
});
if (IS_PROD) {
config.plugin("webpack-report").use(BundleAnalyzerPlugin, [{
analyzerMode: "static"
}]);
}
},
configureWebpack: config = >{
const plugins = [];
if (IS_PROD) {
plugins.push(new CompressionWebpackPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: productionGzipExtensions,
threshold: 10240,
minRatio: 0.8
}));
}
config.plugins = [...config.plugins, ...plugins];
},
css: {
extract: IS_PROD,
requireModuleExtension: false,
loaderOptions: {
less: {
globalVars: {
primary: '#333'
}
}
}
},
devServer: {
overlay: {
warnings: true,
errors: true
},
host: "localhost",
port: 8080,
https: false,
open: false,
hotOnly: true,
proxy: {
"/api": {
target: "http://172.11.11.11:7071",
changeOrigin: true,
secure: false,
pathRewrite: {
"^/api": "/"
}
},
"/api2": {
target: "http://172.12.12.12:2018",
changeOrigin: true,
secure: false,
pathRewrite: {
"^/api2": "/"
}
},
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了