chore: 更新域名并添加鸿蒙构建产物拷贝逻辑
1. 修改站点基础请求域名从xcx6到xcx2 2. 新增mp-harmony构建完成后自动拷贝产物到ascf_src目录的逻辑 3. 限制微信小程序专属分包加载插件仅在微信平台生效 4. 针对鸿蒙平台调整压缩配置,保留console用于调试
This commit is contained in:
2
site.js
2
site.js
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
baseUrl: "https://xcx6.aigc-quickapp.com/",//修改域名
|
baseUrl: "https://xcx2.aigc-quickapp.com/",//修改域名
|
||||||
uniacid: 2847,//后台对应uniacid
|
uniacid: 2847,//后台对应uniacid
|
||||||
};
|
};
|
||||||
171
vue.config.js
171
vue.config.js
@@ -193,6 +193,9 @@ class VersionInjectPlugin {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('补丁脚本执行失败:', e.message);
|
console.error('补丁脚本执行失败:', e.message);
|
||||||
}
|
}
|
||||||
|
// 拷贝构建产物到 ascf_src
|
||||||
|
console.log('\n🚀 mp-harmony 生产构建完成,拷贝产物到 ascf_src 目录...');
|
||||||
|
this._copyMpHarmonyBuild();
|
||||||
} else if (platform === 'h5' && UNI_SCRIPT) {
|
} else if (platform === 'h5' && UNI_SCRIPT) {
|
||||||
this._zipH5Build(compilation);
|
this._zipH5Build(compilation);
|
||||||
}
|
}
|
||||||
@@ -293,6 +296,58 @@ class VersionInjectPlugin {
|
|||||||
console.error('H5 ZIP 打包失败:', e.message);
|
console.error('H5 ZIP 打包失败:', e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_copyMpHarmonyBuild() {
|
||||||
|
const sourceDir = path.join(__dirname, 'unpackage', 'dist', 'build', '.mp-harmony');
|
||||||
|
const destDir = path.join(__dirname, 'stub-app-projects', 'mp-harmony', 'ascf', 'ascf_src');
|
||||||
|
|
||||||
|
console.log(`\n📋 拷贝鸿蒙构建产物...`);
|
||||||
|
console.log(` 源: ${sourceDir}`);
|
||||||
|
console.log(` 目标: ${destDir}`);
|
||||||
|
|
||||||
|
// 检查源目录是否存在
|
||||||
|
if (!fs.existsSync(sourceDir)) {
|
||||||
|
console.error(`❌ 源目录不存在: ${sourceDir}`);
|
||||||
|
throw new Error(`鸿蒙构建产物目录不存在: ${sourceDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 清空目标目录(失败不影响后续拷贝)
|
||||||
|
if (fs.existsSync(destDir)) {
|
||||||
|
try {
|
||||||
|
fs.rmSync(destDir, { recursive: true, force: true });
|
||||||
|
console.log(' ✅ 已清空目标目录');
|
||||||
|
} catch (cleanErr) {
|
||||||
|
console.warn(` ⚠️ 清空目标目录失败,将尝试覆盖: ${cleanErr.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建目标目录
|
||||||
|
fs.mkdirSync(destDir, { recursive: true });
|
||||||
|
|
||||||
|
// 拷贝函数
|
||||||
|
const copyDir = (src, dest) => {
|
||||||
|
if (!fs.existsSync(src)) return;
|
||||||
|
fs.mkdirSync(dest, { recursive: true });
|
||||||
|
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||||
|
for (const entry of entries) {
|
||||||
|
const srcPath = path.join(src, entry.name);
|
||||||
|
const destPath = path.join(dest, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
copyDir(srcPath, destPath);
|
||||||
|
} else {
|
||||||
|
fs.copyFileSync(srcPath, destPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
copyDir(sourceDir, destDir);
|
||||||
|
console.log(' ✅ 拷贝完成');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(` ❌ 拷贝失败: ${e.message}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出配置
|
// 导出配置
|
||||||
@@ -303,20 +358,24 @@ module.exports = {
|
|||||||
|
|
||||||
if (config.mode === 'production') {
|
if (config.mode === 'production') {
|
||||||
console.log('开始尝试配置极限压缩');
|
console.log('开始尝试配置极限压缩');
|
||||||
// 配置zion-uniapp-mp-load-package插件
|
|
||||||
config.plugins.push(new zionUniMpLoadPackagePlugin({
|
if (process.env.UNI_PLATFORM === 'mp-weixin') {
|
||||||
optimization: {
|
// 配置zion-uniapp-mp-load-package插件
|
||||||
minimize: true,
|
config.plugins.push(new zionUniMpLoadPackagePlugin({
|
||||||
moduleIds: 'named'
|
optimization: {
|
||||||
},
|
minimize: true,
|
||||||
packages: [
|
moduleIds: 'named'
|
||||||
'pages',
|
},
|
||||||
'pages_tool',
|
packages: [
|
||||||
'pages_goods',
|
'pages',
|
||||||
'pages_order',
|
'pages_tool',
|
||||||
'pages_promotion'
|
'pages_goods',
|
||||||
]
|
'pages_order',
|
||||||
}));
|
'pages_promotion'
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 确保minimizer数组存在
|
// 确保minimizer数组存在
|
||||||
if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) {
|
if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) {
|
||||||
@@ -332,55 +391,59 @@ module.exports = {
|
|||||||
config.optimization.minimizer[terserPluginIndex].options = {};
|
config.optimization.minimizer[terserPluginIndex].options = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置terserOptions - 极限压缩配置
|
// 区分平台配置压缩选项
|
||||||
config.optimization.minimizer[terserPluginIndex].options.terserOptions = {
|
const isMpHarmony = process.env.UNI_PLATFORM === 'mp-harmony';
|
||||||
|
|
||||||
|
// 基础压缩配置(通用)
|
||||||
|
const terserOptions = {
|
||||||
compress: {
|
compress: {
|
||||||
drop_console: true, // 去除所有console语句
|
drop_console: !isMpHarmony, // 鸿蒙保留 console 用于调试
|
||||||
drop_debugger: true, // 去除debugger语句
|
drop_debugger: !isMpHarmony,
|
||||||
dead_code: true, // 移除死代码
|
dead_code: true,
|
||||||
unused: true, // 移除未使用的变量
|
unused: true,
|
||||||
toplevel: true, // 清理顶层作用域未使用的变量
|
toplevel: true,
|
||||||
passes: 10, // 增加压缩次数以获得更好的压缩效果
|
passes: 10,
|
||||||
sequences: true, // 合并连续的变量声明
|
sequences: true,
|
||||||
evaluate: true, // 提前计算常量表达式
|
evaluate: true,
|
||||||
reduce_vars: true, // 合并或移除变量
|
reduce_vars: true,
|
||||||
join_vars: true, // 合并变量声明
|
join_vars: true,
|
||||||
conditionals: true, // 优化条件表达式
|
conditionals: true,
|
||||||
comparisons: true, // 优化比较操作
|
comparisons: true,
|
||||||
booleans: true, // 优化布尔表达式
|
booleans: true,
|
||||||
typeofs: true, // 优化typeof操作
|
typeofs: true,
|
||||||
collapse_vars: true, // 折叠定义后不再修改的变量
|
collapse_vars: true,
|
||||||
reduce_funcs: true, // 合并或移除未使用的函数
|
reduce_funcs: true,
|
||||||
inline: true, // 内联简单函数
|
inline: true,
|
||||||
side_effects: true, // 移除有副作用的代码
|
side_effects: true,
|
||||||
keep_fargs: false, // 移除未使用的函数参数
|
keep_fargs: false,
|
||||||
keep_fnames: false, // 不保留函数名称
|
keep_fnames: false,
|
||||||
pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 标记为纯函数的console方法
|
pure_funcs: isMpHarmony ? [] : ['console.log', 'console.warn', 'console.error', 'console.info'],
|
||||||
pure_getters: true, // 假设getter函数没有副作用
|
pure_getters: true,
|
||||||
unsafe_math: true, // 优化数学表达式如 Math.sin(3) → 预计算值
|
unsafe_math: true,
|
||||||
},
|
},
|
||||||
format: {
|
format: {
|
||||||
ascii_only: true, // 确保输出ASCII字符
|
ascii_only: true,
|
||||||
comments: false, // 去除所有注释
|
comments: false,
|
||||||
beautify: false, // 不美化输出
|
beautify: false,
|
||||||
ecma: 5, // 输出兼容ECMAScript 5
|
ecma: 5,
|
||||||
wrap_func_args: false, // 不包裹函数参数
|
wrap_func_args: false,
|
||||||
bracketize: true, // 使用大括号包裹所有块
|
bracketize: true,
|
||||||
quote_style: 1 // 使用单引号
|
quote_style: 1
|
||||||
},
|
},
|
||||||
parse: {
|
parse: {
|
||||||
ecma: 8, // 使用ECMAScript 8解析
|
ecma: 8,
|
||||||
bare_returns: true // 允许顶级return语句
|
bare_returns: true
|
||||||
},
|
},
|
||||||
mangle: {
|
mangle: {
|
||||||
toplevel: true, // 混淆顶层作用域的变量名
|
toplevel: true,
|
||||||
keep_fnames: false, // 不保留函数名称
|
keep_fnames: false,
|
||||||
keep_classnames: false // 不保留类名称
|
keep_classnames: false
|
||||||
},
|
},
|
||||||
module: false, // 不是ES模块
|
module: false,
|
||||||
sourceMap: false // 不生成source map
|
sourceMap: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config.optimization.minimizer[terserPluginIndex].options.terserOptions = terserOptions;
|
||||||
console.log('配置极限压缩完成');
|
console.log('配置极限压缩完成');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user