Signed-off-by: laibo <laibo2@huawei.com>
This commit is contained in:
laibo
2022-03-03 10:44:10 +08:00
parent 44398c6a43
commit e693ae0066
+33 -9
View File
@@ -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);