From e693ae00664a017273cf46005e87fb5d65234fab Mon Sep 17 00:00:00 2001 From: laibo Date: Thu, 3 Mar 2022 10:44:10 +0800 Subject: [PATCH] laibo2@huawei.com Signed-off-by: laibo --- ace-loader/src/resource-plugin.js | 42 ++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/ace-loader/src/resource-plugin.js b/ace-loader/src/resource-plugin.js index 041ff5a..465d479 100644 --- a/ace-loader/src/resource-plugin.js +++ b/ace-loader/src/resource-plugin.js @@ -293,19 +293,43 @@ function buildManifest(manifest) { } function loadWorker(entryObj) { - const workerPath = path.resolve(input, 'workers'); - if (fs.existsSync(workerPath)) { - const workerFiles = []; - readFile(workerPath, workerFiles); - workerFiles.forEach((item) => { - if (/\.js$/.test(item)) { - const relativePath = path.relative(workerPath, item).replace(/\.js$/, ''); - entryObj[`./workers/` + relativePath] = item; + if(validateWorkOption()) { + const workerConfig = JSON.parse(fs.readFileSync(process.env.aceWorkPath).toString()); + workerConfig.forEach(worker => { + const relativePath = path.ralative(process.env.projectPath, worker); + if (filterWorker(relativePath)) { + entryObj[relativePath.replace(/\.(ts|js)$/,'')] = worker; } - }); + }) + } else { + const workerPath = path.resolve(input, 'workers'); + if (fs.existsSync(workerPath)) { + const workerFiles = []; + readFile(workerPath, workerFiles); + workerFiles.forEach((item) => { + if (/\.js$/.test(item)) { + const relativePath = path.relative(workerPath, item).replace(/\.js$/, ''); + entryObj[`./workers/` + relativePath] = item; + } + }); + } } } +function validateWorkOption() { + if (process.env.aceWorkPath && fs.existsSync(process.env.aceWorkPath)) { + const workerConfig = JSON.parse(fs.readFileSync(process.env.aceWorkPath).toString()); + if(workerConfig.workers) { + return true; + } + } + return false; +} + +function filterWorker(workerPath) { + return /\.(ts|js)$/.test(workerPath) && !/^\.\./.test(workerPath); +} + function readFile(dir, utFiles) { try { const files = fs.readdirSync(dir);