diff --git a/ace-loader/src/genAbc-plugin.js b/ace-loader/src/genAbc-plugin.js index a4de364..b03c7a9 100644 --- a/ace-loader/src/genAbc-plugin.js +++ b/ace-loader/src/genAbc-plugin.js @@ -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())) { diff --git a/ace-loader/src/genBin-plugin.js b/ace-loader/src/genBin-plugin.js index 16d372a..adfadda 100644 --- a/ace-loader/src/genBin-plugin.js +++ b/ace-loader/src/genBin-plugin.js @@ -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())) { diff --git a/ace-loader/webpack.rich.config.js b/ace-loader/webpack.rich.config.js index b899035..1e21961 100644 --- a/ace-loader/webpack.rich.config.js +++ b/ace-loader/webpack.rich.config.js @@ -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