mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-18 16:04:32 -04:00
fix worker debug bug. Signed-off-by: lihong <lihong67@huawei.com> Change-Id: If5660b3881aee7de4be0a7e666ab6c51c8c7a107
This commit is contained in:
+20
-17
@@ -236,18 +236,9 @@ function setEntrance(abilityConfig, abilityPages) {
|
||||
}
|
||||
}
|
||||
|
||||
function loadWorker(projectConfig) {
|
||||
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)$/,'').replace(/\\/g, '/')] = worker;
|
||||
}
|
||||
})
|
||||
function loadWorker(projectConfig, workerFileEntry) {
|
||||
if (workerFileEntry) {
|
||||
projectConfig.entryObj = Object.assign(projectConfig.entryObj, workerFileEntry);
|
||||
} else {
|
||||
const workerPath = path.resolve(projectConfig.projectPath, WORKERS_DIR);
|
||||
if (fs.existsSync(workerPath)) {
|
||||
@@ -255,7 +246,8 @@ function loadWorker(projectConfig) {
|
||||
readFile(workerPath, workerFiles);
|
||||
workerFiles.forEach((item) => {
|
||||
if (/\.(ts|js)$/.test(item)) {
|
||||
const relativePath = path.relative(workerPath, item).replace(/\.(ts|js)$/, '');
|
||||
const relativePath = path.relative(workerPath, item)
|
||||
.replace(/\.(ts|js)$/, '').replace(/\\/g, '/');
|
||||
projectConfig.entryObj[`./${WORKERS_DIR}/` + relativePath] = item;
|
||||
}
|
||||
})
|
||||
@@ -263,14 +255,24 @@ function loadWorker(projectConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
function validateWorkOption() {
|
||||
function readWorkerFile() {
|
||||
const workerFileEntry = {};
|
||||
if (projectConfig.aceBuildJson && fs.existsSync(projectConfig.aceBuildJson)) {
|
||||
const workerConfig = JSON.parse(fs.readFileSync(projectConfig.aceBuildJson).toString());
|
||||
if(workerConfig.workers) {
|
||||
return true;
|
||||
if (workerConfig.workers) {
|
||||
workerConfig.workers.forEach(worker => {
|
||||
if (!/\.(ts|js)$/.test(worker)) {
|
||||
worker += '.ts';
|
||||
}
|
||||
const relativePath = path.relative(projectConfig.projectPath, worker);
|
||||
if (filterWorker(relativePath)) {
|
||||
workerFileEntry[relativePath.replace(/\.(ts|js)$/, '').replace(/\\/g, '/')] = worker;
|
||||
}
|
||||
});
|
||||
return workerFileEntry;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
function filterWorker(workerPath) {
|
||||
@@ -337,3 +339,4 @@ exports.readAppResource = readAppResource;
|
||||
exports.resources = resources;
|
||||
exports.loadWorker = loadWorker;
|
||||
exports.abilityConfig = abilityConfig;
|
||||
exports.readWorkerFile = readWorkerFile;
|
||||
|
||||
@@ -26,7 +26,8 @@ const {
|
||||
readAppResource,
|
||||
resources,
|
||||
loadWorker,
|
||||
abilityConfig
|
||||
abilityConfig,
|
||||
readWorkerFile
|
||||
} = require('./main');
|
||||
const { ResultStates } = require('./lib/compile_info');
|
||||
const { processUISyntax } = require('./lib/process_ui_syntax');
|
||||
@@ -251,12 +252,19 @@ function setCopyPluginConfig(config) {
|
||||
config.plugins.push(new CopyPlugin({ patterns: copyPluginPattrens }));
|
||||
}
|
||||
|
||||
function setOptimizationConfig(config) {
|
||||
function excludeWorker(workerFile, name) {
|
||||
if (workerFile) {
|
||||
return Object.keys(workerFile).includes(name);
|
||||
}
|
||||
return /^\.\/workers\//.test(name);
|
||||
}
|
||||
|
||||
function setOptimizationConfig(config, workerFile) {
|
||||
if (process.env.compileMode !== 'moduleJson' && abilityConfig.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: {
|
||||
@@ -282,10 +290,11 @@ module.exports = (env, argv) => {
|
||||
setProjectConfig(env);
|
||||
loadEntryObj(projectConfig);
|
||||
initConfig(config);
|
||||
setOptimizationConfig(config);
|
||||
const workerFile = readWorkerFile();
|
||||
setOptimizationConfig(config, workerFile);
|
||||
setCopyPluginConfig(config);
|
||||
if (env.isPreview !== "true") {
|
||||
loadWorker(projectConfig);
|
||||
loadWorker(projectConfig, workerFile);
|
||||
if (env.compilerType && env.compilerType === 'ark') {
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
if (env.arkFrontendDir) {
|
||||
|
||||
Reference in New Issue
Block a user