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; // 图形化打包详情 // const BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; 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: 8089, https: false, hotOnly: false, disableHostCheck: true, proxy: { "/domain": { // target: "http://localhost:8089", // 测试环境 // target: "http://192.168.18.236:18888/", // 线上测试环境 // target: "http://park.test.hhrchina.com/", target: "http://xiaokunshan.cn", // 谢老师 // target: "http://192.168.18.138:18888/", // 阚老师 // target: "http://192.168.18.7:18888/", // 何老师 // target: "http://192.168.30.48:18888/", 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")) .set("@mixin", resolve("./src/mixin")); }, css: { loaderOptions: { sass: { // 根据自己样式文件的位置调整 prependData: `@import "@assets/scss/global.scss";`, //这里的@是别名 }, }, }, 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, }) // new BundleAnalyzer() ); } config.plugins = [...config.plugins, ...plugins]; }, };