fix worker debug bug.

Signed-off-by: lihong <lihong67@huawei.com>
Change-Id: If5179282320e9e4b7aa59897b7d105226842ad62
This commit is contained in:
lihong
2022-05-26 23:14:42 +08:00
parent 3f9c94fd86
commit 3f86c5660a
3 changed files with 46 additions and 18 deletions
+26 -1
View File
@@ -153,6 +153,30 @@ function checkMultiResourceBuild(aceBuildJson) {
}
}
function readWorkerFile() {
const workerEntryObj = {};
if (process.env.aceBuildJson && fs.existsSync(process.env.aceBuildJson)) {
const workerConfig = JSON.parse(fs.readFileSync(process.env.aceBuildJson).toString());
if(workerConfig.workers) {
workerConfig.workers.forEach(worker => {
if (!/\.(js)$/.test(worker)) {
worker += '.js';
}
const relativePath = path.relative(process.env.projectPath, worker);
if (filterWorker(relativePath)) {
workerEntryObj[relativePath.replace(/\.(ts|js)$/,'').replace(/\\/g, '/')] = worker;
}
})
return workerEntryObj;
}
}
return null;
}
function filterWorker(workerPath) {
return /\.(ts|js)$/.test(workerPath);
}
module.exports = {
deleteFolderRecursive: deleteFolderRecursive,
readManifest: readManifest,
@@ -160,5 +184,6 @@ module.exports = {
compileCardModule: compileCardModule,
hashProjectPath: hashProjectPath,
checkMultiResourceBuild: checkMultiResourceBuild,
multiResourceBuild: multiResourceBuild
multiResourceBuild: multiResourceBuild,
readWorkerFile: readWorkerFile,
};
+7 -13
View File
@@ -33,6 +33,7 @@ let shareThemePath = '';
let internalThemePath = '';
let resourcesPath;
let sharePath;
let workerFile;
function copyFile(input, output) {
try {
@@ -112,7 +113,7 @@ function toCopyFile(file, outputFile, fileStat) {
}
class ResourcePlugin {
constructor(input_, output_, manifestFilePath_, watchCSSFiles_) {
constructor(input_, output_, manifestFilePath_, watchCSSFiles_, workerFile_ = null) {
input = input_;
output = output_;
manifestFilePath = manifestFilePath_;
@@ -121,6 +122,7 @@ class ResourcePlugin {
internalThemePath = path.join(input_, 'resources/styles');
resourcesPath = path.resolve(input_, 'resources');
sharePath = path.resolve(input_, '../share/resources');
workerFile = workerFile_;
}
apply(compiler) {
compiler.hooks.beforeCompile.tap('resource Copy', () => {
@@ -331,17 +333,8 @@ function buildManifest(manifest) {
}
function loadWorker(entryObj) {
if(validateWorkOption()) {
const workerConfig = JSON.parse(fs.readFileSync(process.env.aceBuildJson).toString());
workerConfig.workers.forEach(worker => {
if (!/\.(js)$/.test(worker)) {
worker += '.js';
}
const relativePath = path.relative(process.env.projectPath, worker);
if (filterWorker(relativePath)) {
entryObj[relativePath.replace(/\.(ts|js)$/,'').replace(/\\/g, '/')] = worker;
}
})
if (workerFile) {
entryObj = Object.assign(entryObj, workerFile);
} else {
const workerPath = path.resolve(input, 'workers');
if (fs.existsSync(workerPath)) {
@@ -349,7 +342,8 @@ function loadWorker(entryObj) {
readFile(workerPath, workerFiles);
workerFiles.forEach((item) => {
if (/\.js$/.test(item)) {
const relativePath = path.relative(workerPath, item).replace(/\.js$/, '');
const relativePath = path.relative(workerPath, item)
.replace(/\.js$/, '').replace(/\\/g, '/');
entryObj[`./workers/` + relativePath] = item;
}
});
+13 -4
View File
@@ -35,7 +35,8 @@ const {
loadEntryObj,
compileCardModule,
hashProjectPath,
checkMultiResourceBuild
checkMultiResourceBuild,
readWorkerFile
} = require('./main.product')
const richModule = {
@@ -242,8 +243,16 @@ function existsPackageJson(config, rootPackageJsonPath, modulePackageJsonPath) {
}
}
function excludeWorker(workerFile, name) {
if (workerFile) {
return Object.keys(workerFile).includes(name);
}
return /^\.\/workers\//.test(name);
}
module.exports = (env) => {
setConfigs(env);
const workerFile = readWorkerFile();
if (process.env.compileMode === 'moduleJson') {
compileCardModule(env);
config.entry = {};
@@ -258,7 +267,7 @@ module.exports = (env) => {
config.output.path = path.resolve(__dirname, process.env.buildPath)
config.plugins = [
new ResourcePlugin(process.env.projectPath, process.env.buildPath,
process.env.aceManifestPath, process.env.watchCSSFiles),
process.env.aceManifestPath, process.env.watchCSSFiles, workerFile),
new ResultStates({
build: process.env.buildPath
}),
@@ -304,11 +313,11 @@ module.exports = (env) => {
notPreview(env)
}
} else {
if (process.env.abilityType === 'page') {
if (process.env.compileMode !== 'moduleJson' && process.env.abilityType === 'page') {
config.optimization = {
splitChunks: {
chunks(chunk) {
return !/^\.\/workers\//.test(chunk.name) && !/^\.\/TestAbility/.test(chunk.name);
return !excludeWorker(workerFile, chunk.name) && !/^\.\/TestAbility/.test(chunk.name);
},
minSize: 0,
cacheGroups: {