mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-21 06:05:27 -04:00
fix check works file
Signed-off-by: zhangrengao <zhangrengao1@huawei.com> Change-Id: I8ddaf7d22d78df2f38f5d84138ee4ede6987f4be
This commit is contained in:
@@ -42,13 +42,15 @@ let isDebug = false;
|
||||
let arkDir;
|
||||
let nodeJs;
|
||||
let intermediateJsBundle = [];
|
||||
let workerFile = null;
|
||||
|
||||
class GenAbcPlugin {
|
||||
constructor(output_, arkDir_, nodeJs_, isDebug_) {
|
||||
constructor(output_, arkDir_, nodeJs_, workerFile_, isDebug_) {
|
||||
output = output_;
|
||||
arkDir = arkDir_;
|
||||
nodeJs = nodeJs_;
|
||||
isDebug = isDebug_;
|
||||
workerFile = workerFile_;
|
||||
}
|
||||
apply(compiler) {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-win'))) {
|
||||
@@ -66,7 +68,7 @@ class GenAbcPlugin {
|
||||
// choice *.js
|
||||
if (output && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source();
|
||||
if (key.search('workers/') !== 0 && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
if (checkWorksFile(key, workerFile) && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
newContent = forward + newContent + last;
|
||||
}
|
||||
if (key === 'commons.js' || key === 'vendors.js') {
|
||||
@@ -83,6 +85,22 @@ class GenAbcPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
function checkWorksFile(assetPath, workerFile) {
|
||||
if (workerFile === null) {
|
||||
if (assetPath.search("./workers/")) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
for (const key in workerFile) {
|
||||
if (key === assetPath || workerFile[key] === assetPath) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function writeFileSync(inputString, output, jsBundleFile) {
|
||||
const parent = path.join(output, '..');
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
|
||||
@@ -38,11 +38,13 @@ const sencondFileEXT = '.c'
|
||||
const lastFileEXT = '.bin'
|
||||
let output
|
||||
let webpackPath
|
||||
let workerFile = null;
|
||||
|
||||
class GenBinPlugin {
|
||||
constructor(output_, webpackPath_) {
|
||||
constructor(output_, webpackPath_, workerFile_) {
|
||||
output = output_
|
||||
webpackPath = webpackPath_
|
||||
workerFile = workerFile_
|
||||
}
|
||||
apply(compiler) {
|
||||
if (!fs.existsSync(path.resolve(webpackPath, 'qjsc.exe')) && !fs.existsSync(path.resolve(webpackPath, 'qjsc'))) {
|
||||
@@ -55,7 +57,7 @@ class GenBinPlugin {
|
||||
// choice *.js
|
||||
if (output && webpackPath && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source()
|
||||
if (key.search('workers/') !== 0) {
|
||||
if (checkWorksFile(key, workerFile)) {
|
||||
newContent = forward + newContent + last
|
||||
}
|
||||
const keyPath = key.replace(/\.js$/, firstFileEXT)
|
||||
@@ -66,6 +68,22 @@ class GenBinPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
function checkWorksFile(assetPath, workerFile) {
|
||||
if (workerFile_ === null) {
|
||||
if (assetPath.search("./workers/")) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
for (const key in workerFile) {
|
||||
if (key === assetPath || workerFile[key] === assetPath) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function writeFileSync(inputString, output, jsBundleFile) {
|
||||
const parent = path.join(output, '..')
|
||||
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
|
||||
|
||||
@@ -201,7 +201,7 @@ function setConfigs(env) {
|
||||
checkMultiResourceBuild(process.env.aceBuildJson);
|
||||
}
|
||||
|
||||
function notPreview(env) {
|
||||
function notPreview(env, workerFile) {
|
||||
config.plugins.push(new ModuleCollectionPlugin())
|
||||
if (env.compilerType && env.compilerType === 'ark') {
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
@@ -212,7 +212,7 @@ function notPreview(env) {
|
||||
if (env.nodeJs) {
|
||||
nodeJs = env.nodeJs;
|
||||
}
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs,
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir, nodeJs, workerFile,
|
||||
env.buildMode === 'debug'))
|
||||
if (env.buildMode === 'release' && process.env.DEVICE_LEVEL !== 'card') {
|
||||
config.output.path = path.join(process.env.cachePath, "releaseAssets",
|
||||
@@ -223,7 +223,7 @@ function notPreview(env) {
|
||||
let deviceArr = env.deviceType.split(/,/)
|
||||
let isDefault = deviceArr.indexOf('tv') >= 0 || deviceArr.indexOf('wearable') >= 0 ? true : false
|
||||
if (isDefault) {
|
||||
config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin')))
|
||||
config.plugins.push(new GenBinPlugin(process.env.buildPath, path.join(__dirname, 'bin', workerFile)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,7 +310,7 @@ module.exports = (env) => {
|
||||
config.module = cardModule
|
||||
config.plugins.push(new AfterEmitPlugin())
|
||||
if (env.isPreview !== "true") {
|
||||
notPreview(env)
|
||||
notPreview(env, workerFile)
|
||||
}
|
||||
} else {
|
||||
if (process.env.compileMode !== 'moduleJson' && process.env.abilityType === 'page') {
|
||||
@@ -338,7 +338,7 @@ module.exports = (env) => {
|
||||
}
|
||||
}
|
||||
if (env.isPreview !== "true") {
|
||||
notPreview(env)
|
||||
notPreview(env, workerFile)
|
||||
}
|
||||
if (env.sourceMap === 'none') {
|
||||
config.devtool = false
|
||||
|
||||
Reference in New Issue
Block a user