From 30fef9770a8cef065f1ceea32140c341505cb65c Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Mon, 5 Jan 2026 15:46:26 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0vue.config.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local.config.js.example | 10 ++- vue.config.js | 128 +++++++++++++++++++-------------------- 2 files changed, 72 insertions(+), 66 deletions(-) diff --git a/.local.config.js.example b/.local.config.js.example index 738b89e..fd74a22 100644 --- a/.local.config.js.example +++ b/.local.config.js.example @@ -9,7 +9,15 @@ const localDevConfig = ({ '2285': { // 数码喷墨墨水 uniacid: 2285, domain: 'https://xcx.aigc-quickapp.com/', + }, + '2724': { // 德龙生物肥料 + uniacid: 2724, + domain: 'https://xcx.aigc-quickapp.com/', }, + '2777': { // 养老服务 + uniacid: 2777, + domain: 'https://xcx.aigc-quickapp.com/', + }, '1': { // 开发平台 uniacid: 1, domain: 'https://dev.aigc-quickapp.com', @@ -18,6 +26,6 @@ const localDevConfig = ({ uniacid: 1, domain: 'https://test.aigc-quickapp.com', }, -})['2285']; // 选择要使用的环境配置 +})['2724']; // 选择要使用的环境配置 export default localDevConfig; \ No newline at end of file diff --git a/vue.config.js b/vue.config.js index ebf8b7f..c89a95b 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,73 +1,71 @@ module.exports = { productionSourceMap: false, configureWebpack: config => { - if (process.env.NODE_ENV === 'production') { - console.log('生产环境下开启极限压缩'); - - // 确保minimizer数组存在 - if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) { - // 查找TerserWebpackPlugin实例,而不是依赖索引 - const terserPluginIndex = config.optimization.minimizer.findIndex(plugin => { - return plugin.constructor && plugin.constructor.name === 'TerserWebpackPlugin' || - (plugin.options && plugin.options.terserOptions); - }); - - if (terserPluginIndex !== -1) { - // 确保options对象存在 - if (!config.optimization.minimizer[terserPluginIndex].options) { - config.optimization.minimizer[terserPluginIndex].options = {}; - } - - // 设置terserOptions - 极限压缩配置 - config.optimization.minimizer[terserPluginIndex].options.terserOptions = { - compress: { - drop_console: true, // 去除所有console语句 - drop_debugger: true, // 去除debugger语句 - dead_code: true, // 移除死代码 - unused: true, // 移除未使用的变量 - toplevel: true, // 清理顶层作用域未使用的变量 - passes: 5, // 增加压缩次数以获得更好的压缩效果 - sequences: true, // 合并连续的变量声明 - evaluate: true, // 提前计算常量表达式 - reduce_vars: true, // 合并或移除变量 - join_vars: true, // 合并变量声明 - conditionals: true, // 优化条件表达式 - comparisons: true, // 优化比较操作 - booleans: true, // 优化布尔表达式 - typeofs: true, // 优化typeof操作 - collapse_vars: true, // 折叠定义后不再修改的变量 - reduce_funcs: true, // 合并或移除未使用的函数 - inline: true, // 内联简单函数 - side_effects: true, // 移除有副作用的代码 - keep_fargs: false, // 移除未使用的函数参数 - keep_fnames: false, // 不保留函数名称 - pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 标记为纯函数的console方法 - pure_getters: true // 假设getter函数没有副作用 - }, - format: { - ascii_only: true, // 确保输出ASCII字符 - comments: false, // 去除所有注释 - beautify: false, // 不美化输出 - ecma: 5, // 输出兼容ECMAScript 5 - wrap_func_args: false, // 不包裹函数参数 - bracketize: true, // 使用大括号包裹所有块 - quote_style: 1 // 使用单引号 - }, - parse: { - ecma: 8, // 使用ECMAScript 8解析 - bare_returns: true // 允许顶级return语句 - }, - mangle: { - toplevel: true, // 混淆顶层作用域的变量名 - keep_fnames: false, // 不保留函数名称 - keep_classnames: false // 不保留类名称 - }, - module: false, // 不是ES模块 - sourceMap: false // 不生成source map - }; + console.log('开始尝试配置极限压缩'); - console.log('terserOptions配置完成'); + // 确保minimizer数组存在 + if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) { + // 查找TerserWebpackPlugin实例,而不是依赖索引 + const terserPluginIndex = config.optimization.minimizer.findIndex(plugin => { + return plugin.constructor && plugin.constructor.name === 'TerserWebpackPlugin' || + (plugin.options && plugin.options.terserOptions); + }); + + if (terserPluginIndex !== -1) { + // 确保options对象存在 + if (!config.optimization.minimizer[terserPluginIndex].options) { + config.optimization.minimizer[terserPluginIndex].options = {}; } + + // 设置terserOptions - 极限压缩配置 + config.optimization.minimizer[terserPluginIndex].options.terserOptions = { + compress: { + drop_console: true, // 去除所有console语句 + drop_debugger: true, // 去除debugger语句 + dead_code: true, // 移除死代码 + unused: true, // 移除未使用的变量 + toplevel: true, // 清理顶层作用域未使用的变量 + passes: 5, // 增加压缩次数以获得更好的压缩效果 + sequences: true, // 合并连续的变量声明 + evaluate: true, // 提前计算常量表达式 + reduce_vars: true, // 合并或移除变量 + join_vars: true, // 合并变量声明 + conditionals: true, // 优化条件表达式 + comparisons: true, // 优化比较操作 + booleans: true, // 优化布尔表达式 + typeofs: true, // 优化typeof操作 + collapse_vars: true, // 折叠定义后不再修改的变量 + reduce_funcs: true, // 合并或移除未使用的函数 + inline: true, // 内联简单函数 + side_effects: true, // 移除有副作用的代码 + keep_fargs: false, // 移除未使用的函数参数 + keep_fnames: false, // 不保留函数名称 + pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 标记为纯函数的console方法 + pure_getters: true // 假设getter函数没有副作用 + }, + format: { + ascii_only: true, // 确保输出ASCII字符 + comments: false, // 去除所有注释 + beautify: false, // 不美化输出 + ecma: 5, // 输出兼容ECMAScript 5 + wrap_func_args: false, // 不包裹函数参数 + bracketize: true, // 使用大括号包裹所有块 + quote_style: 1 // 使用单引号 + }, + parse: { + ecma: 8, // 使用ECMAScript 8解析 + bare_returns: true // 允许顶级return语句 + }, + mangle: { + toplevel: true, // 混淆顶层作用域的变量名 + keep_fnames: false, // 不保留函数名称 + keep_classnames: false // 不保留类名称 + }, + module: false, // 不是ES模块 + sourceMap: false // 不生成source map + }; + + console.log('配置极限压缩完成'); } } }