!293 对worker文件过滤编译

Merge pull request !293 from laibo102/master
This commit is contained in:
openharmony_ci
2022-03-09 03:47:35 +00:00
committed by Gitee
2 changed files with 38 additions and 11 deletions
+36 -8
View File
@@ -58,6 +58,7 @@ function initProjectConfig(projectConfig) {
process.env.aceSuperVisualPath
projectConfig.hashProjectPath = projectConfig.hashProjectPath ||
hashProjectPath(projectConfig.projectPath)
projectConfig.aceBuildJson = projectConfig.aceBuildJson || process.env.aceBuildJson;
}
function loadEntryObj(projectConfig) {
@@ -226,19 +227,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)) {
+2 -3
View File
@@ -75,7 +75,6 @@ export class ResultStates {
private modulePaths: Set<string> = 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(