feat(scripts): add harmony component placeholder injection logic

新增鸿蒙组件级componentPlaceholder自动注入脚本,解决diy组件编译为asyncComponent导致的运行时报错,自动遍历处理非页面组件的json配置文件,同时添加异常捕获避免构建中断
This commit is contained in:
2026-07-10 17:28:52 +08:00
parent 2276291a4b
commit 6178f699ed
2 changed files with 193 additions and 0 deletions

View File

@@ -58,6 +58,19 @@ async function copyAssets(mode = 'production') {
}
await Promise.all(copyPromises);
// 给所有子组件 .json 注入 componentPlaceholder, 避免 "diy-* is asyncComponent" 报错.
// 见 scripts/harmony-component-placeholder.js 说明. 该脚本跳过页面级, 只处理组件.
try {
const { execFileSync } = require('child_process');
execFileSync(process.execPath, [
path.join(__dirname, 'harmony-component-placeholder.js'),
destDir,
], { stdio: 'inherit', cwd });
} catch (e) {
console.warn('[harmony.patch] ⚠️ harmony-component-placeholder 注入失败:', e.message);
}
console.log('HarmonyOS 资源拷贝完成');
} catch (err) {
console.error('发生错误:', err);