const path = require("path"); const CompressionWebpackPlugin = require("compression-webpack-plugin"); const isProd = process.env.NODE_ENV === "production"; function resolve(dir) { return path.join(__dirname, dir); } module.exports = { publicPath: process.env.NODE_ENV === "production" ? "/" : "/", chainWebpack: (config) => { config.resolve.alias.set("@", resolve("src")); }, configureWebpack: (config) => { /* gzip压缩,nginx需要开启gzip*/ if (isProd) { // 配置webpack 压缩 config.plugins.push( new CompressionWebpackPlugin({ test: /\.js$|\.html$|\.css$/, // 超过4kb压缩 threshold: 4096, }) ); } // 添加 CDN 配置 config.plugins.forEach((plugin) => { if (plugin.constructor.name === 'HtmlWebpackPlugin') { plugin.options.cdn = { js: [] }; } }); }, devServer: { open: true, https: false, proxy: { "/api": { target: "http://18.163.50.191:19005/api", changeOrigin: true, pathRewrite: { "^/api": "", }, }, }, }, };