diff --git a/compiler/main.js b/compiler/main.js index 9762056faca129be09d24ccf86e8b293281352b0..372ce24f66ce5569457ad093e3e2817232d01bd2 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -57,6 +57,7 @@ function initProjectConfig(projectConfig) { process.env.aceSuperVisualPath projectConfig.hashProjectPath = projectConfig.hashProjectPath || hashProjectPath(projectConfig.projectPath) + projectConfig.aceBuildJson = projectConfig.aceBuildJson || process.env.aceBuildJson; } function loadEntryObj(projectConfig) { @@ -190,19 +191,46 @@ 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 (validateWorkOption()) { + const workerConfig = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString()); + workerConfig.workers.forEach(worker => { + if (!/\.(ts|js)$/.test(worker)) { + worker += '.ts'; + } + const relativePath = path.relative(projectConfig.projectPath, worker); + if (filterWorker(relativePath)) { + projectConfig.entryObj[relativePath.replace(/\.(ts|js)$/,'')] = worker; } }) + } 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; + } + }) + } } } +function validateWorkOption() { + if (projectConfig.aceBuildJson && fs.existsSync(projectConfig.aceBuildJson)) { + const workerConfig = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString()); + if(workerConfig.workers) { + return true; + } + } + return false; +} + +function filterWorker(workerPath) { + return /\.(ts|js)$/.test(workerPath) && !/^\.\./.test(workerPath); +} + ;(function initSystemResource() { const sysResourcePath = path.resolve('./sysResource.js'); if (fs.existsSync(sysResourcePath)) { diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 6e5fdb4f160bfd58eda8ae95f3b13dfe7e40e7a1..4312b7f40d716dd014e1507e1705836965d5220f 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -75,7 +75,6 @@ export class ResultStates { private modulePaths: Set = new Set([]); public apply(compiler: Compiler): void { - compiler.hooks.compilation.tap('SourcemapFixer', compilation => { compilation.hooks.afterProcessAssets.tap('SourcemapFixer', assets => { Reflect.ownKeys(assets).forEach(key => { @@ -110,14 +109,14 @@ export class ResultStates { stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS }, (assets) => { - const GLOBAL_COMMON_MODULE_CACHE = ` + const GLOBAL_COMMON_MODULE_CACHE = ` globalThis["__common_module_cache__${projectConfig.hashProjectPath}"] =` + ` globalThis["__common_module_cache__${projectConfig.hashProjectPath}"] || {}; globalThis["webpackChunk${projectConfig.hashProjectPath}"].forEach((item)=> { Object.keys(item[1]).forEach((element) => { globalThis["__common_module_cache__${projectConfig.hashProjectPath}"][element] = null; }) - });` + });`; if (assets['commons.js']) { assets['commons.js'] = new CachedSource(