From 27546943e404ea1266ebda824d421cb4b86e523c Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Tue, 1 Mar 2022 13:38:32 +0800 Subject: [PATCH] yangbo198@huawei.com Signed-off-by: yangbo <1442420648@qq.com> Change-Id: Icc9ae5612e7ebcef8da34bd761949d3640cbbc4a --- compiler/main.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index aa25d1a8b..58ef49d73 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -187,16 +187,29 @@ function setEntrance(abilityConfig, abilityPages) { } function loadWorker(projectConfig) { - const workerPath = path.resolve(projectConfig.projectPath, WORKERS_DIR); - if (fs.existsSync(workerPath)) { - const workerFiles = []; - readFile(workerPath, workerFiles); - workerFiles.forEach((item) => { - if (/\.(ts|js)$/.test(item)) { - const relativePath = path.relative(workerPath, item).replace(/\.(ts|js)$/, ''); - projectConfig.entryObj[`./${WORKERS_DIR}/` + relativePath] = item; - } - }) + if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { + const moduleJson = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); + if (moduleJson.ArkUIOption && moduleJson.ArkUIOption.workers) { + moduleJson.ArkUIOption.workers.forEach(worker => { + if (/\.(ts|js)$/.test(worker)) { + const workerPath = path.resolve(projectConfig.projectPath, WORKERS_DIR, worker); + const relativePath = worker.replace(/\.(ts|js)$/, ''); + projectConfig.entryObj[`./${WORKERS_DIR}/` + relativePath] = workerPath; + } + }); + } + } else { + const workerPath = path.resolve(projectConfig.projectPath, WORKERS_DIR); + if (fs.existsSync(workerPath)) { + const workerFiles = []; + readFile(workerPath, workerFiles); + workerFiles.forEach((item) => { + if (/\.(ts|js)$/.test(item)) { + const relativePath = path.relative(workerPath, item).replace(/\.(ts|js)$/, ''); + projectConfig.entryObj[`./${WORKERS_DIR}/` + relativePath] = item; + } + }) + } } } -- Gitee