const path = require("path"); const resolve = dir => path.join(__dirname, dir); const IS_PROD = ["production", "prod"].includes(process.env.NODE_ENV); const CompressionWebpackPlugin = require("compression-webpack-plugin"); const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i; module.exports = { publicPath: "/", // 默认'/',部署应用包时的基本 URL outputDir: "dist", // 'dist', 生产环境构建文件的目录 assetsDir: "pc", // 相对于outputDir的静态资源(js、css、img、fonts)目录 lintOnSave: false, indexPath: "pc.html", runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本 productionSourceMap: false, // 生产环境的 source map devServer: { open: true, index: "index.html", //默认启动serve 打开index页面 port: 8088, https: false, hotOnly: false, disableHostCheck: true, proxy: { "/domain": { // target: "http://192.168.18.138:80", target: "http://localhost:80", changeOrigin: true, pathRewrite: { "^/domain": "", }, }, }, }, chainWebpack: config => { // 修复热更新 config.resolve.symlinks(true); // 添加别名 config.resolve.alias .set("@", resolve("./src")) .set("@assets", resolve("./src/assets")) .set("@api", resolve("./src/api")) .set("@utils", resolve("./src/utils")) .set("@components", resolve("./src/components")) .set("@views", resolve("./src/views")); }, configureWebpack: config => { config.optimization = { runtimeChunk: true, }; const plugins = []; if (IS_PROD) { plugins.push( // 开启gzip new CompressionWebpackPlugin({ filename: "[path].gz[query]", algorithm: "gzip", test: productionGzipExtensions, threshold: 10240, minRatio: 0.8, }) ); } config.plugins = [...config.plugins, ...plugins]; }, };