diff --git a/compiler/main.js b/compiler/main.js index aa25d1a8b5df60a8ad647e0e21c7d24ab7d2965a..58ef49d73edb04aaf58baa0e8235bb4f3210ec59 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; + } + }) + } } }