const path = require("path"); // 引入打包分析文件 const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); // 引入Gzip压缩文件 const CompressionPlugin = require("compression-webpack-plugin"); // 引入js打包工具 const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin"); module.exports = { outputDir:'hz_crm_web', lintOnSave: false, publicPath: process.env.NODE_ENV === "production" ? "/" : "/", runtimeCompiler: true, productionSourceMap: false, //关闭生产环境下的SourceMap映射文件 chainWebpack: (config) => { config.resolve.alias .set("scss_vars", "@/styles/vars.scss") .set("index_scss", "@/styles/index.scss") .set("api", "@/api") .set("utils", "@/utils") .set("components", "@/components") .set("common", "@/common"); config.resolve.extensions.add(".js").add(".vue").add(".json"); config.externals = { // vue: "Vue", echarts: "echarts", }; }, configureWebpack: (config) => { const pluginsPro = []; pluginsPro.push( new CompressionPlugin({ algorithm: "gzip", test: /\.js$|\.html$|\.css$/, // 匹配文件名 minRatio: 0.8, // 压缩率小于1才会压缩 threshold: 10240, // 对超过10k的数据压缩 deleteOriginalAssets: false, // 是否删除未压缩的源文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false(比如删除打包后的gz后还可以加载到原始资源文件) }) ); pluginsPro.push( // js文件压缩 new UglifyJsPlugin({ uglifyOptions: { compress: { drop_debugger: true, drop_console: true, //生产环境自动删除console pure_funcs: ["console.log"], //移除console }, }, sourceMap: false, parallel: true, //使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。 }) ); if (process.env.NODE_ENV === "production") { config.plugins = [...config.plugins, ...pluginsPro]; } }, devServer: { port: "8080", open: true, proxy: { "/adminapi": { target: "http://8.136.199.33:7777", changeOrigin: true, //允许跨域 pathRewrite: { "^/adminapi": "/adminapi", }, }, }, }, };