mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-19 10:15:08 -04:00
@@ -15,7 +15,8 @@
|
||||
|
||||
var path = require('path')
|
||||
var fs = require('fs')
|
||||
var shell = require('shelljs')
|
||||
var shell = require('shelljs');
|
||||
const md5 = require('md5');
|
||||
|
||||
const red = '\u001b[31m';
|
||||
const reset = '\u001b[39m';
|
||||
@@ -133,9 +134,20 @@ function validateCardModule(moduleJsonConfig) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function hashProjectPath(projectPath) {
|
||||
const ASSCIIStart = 65;
|
||||
const ASSCIIEnd = 90;
|
||||
const deviation = 1;
|
||||
process.env.hashProjectPath =
|
||||
String.fromCharCode(Math.floor(Math.random() * (ASSCIIEnd - ASSCIIStart + deviation) + ASSCIIStart)) +
|
||||
md5(projectPath).substring(9, 16) +
|
||||
String.fromCharCode(Math.floor(Math.random() * (ASSCIIEnd - ASSCIIStart + deviation) + ASSCIIStart));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
deleteFolderRecursive: deleteFolderRecursive,
|
||||
readManifest: readManifest,
|
||||
loadEntryObj: loadEntryObj,
|
||||
compileCardModule: compileCardModule
|
||||
compileCardModule: compileCardModule,
|
||||
hashProjectPath: hashProjectPath
|
||||
};
|
||||
@@ -32,17 +32,19 @@ let warningCount = 0;
|
||||
let noteCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
const GLOBAL_COMMON_MODULE_CACHE = `
|
||||
globalThis["__common_module_cache__"] = globalThis["__common_module_cache__"] || {};
|
||||
globalThis["webpackChunkace_loader"].forEach((item)=> {
|
||||
Object.keys(item[1]).forEach((element) => {
|
||||
globalThis["__common_module_cache__"][element] = null;
|
||||
})
|
||||
});`;
|
||||
let GLOBAL_COMMON_MODULE_CACHE;
|
||||
|
||||
class ResultStates {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
GLOBAL_COMMON_MODULE_CACHE = `
|
||||
globalThis["__common_module_cache__${process.env.hashProjectPath}"] =` +
|
||||
` globalThis["__common_module_cache__${process.env.hashProjectPath}"] || {};
|
||||
globalThis["webpackChunk${process.env.hashProjectPath}"].forEach((item)=> {
|
||||
Object.keys(item[1]).forEach((element) => {
|
||||
globalThis["__common_module_cache__${process.env.hashProjectPath}"][element] = null;
|
||||
})
|
||||
});`;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
@@ -115,13 +117,18 @@ class ResultStates {
|
||||
compiler.hooks.compilation.tap('Require', compilation => {
|
||||
JavascriptModulesPlugin.getCompilationHooks(compilation).renderRequire.tap('renderRequire',
|
||||
(source) => {
|
||||
return `var commonCachedModule = globalThis["__common_module_cache__"] ? ` +
|
||||
`globalThis["__common_module_cache__"][moduleId]: null;\n` +
|
||||
return `var commonCachedModule =` +
|
||||
` globalThis["__common_module_cache__${process.env.hashProjectPath}"] ? ` +
|
||||
`globalThis["__common_module_cache__${process.env.hashProjectPath}"]` +
|
||||
`[moduleId]: null;\n` +
|
||||
`if (commonCachedModule) { return commonCachedModule.exports; }\n` +
|
||||
source.replace('// Execute the module function',
|
||||
`if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__"]).indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__"][moduleId] = module;\n}`);
|
||||
`if (globalThis["__common_module_cache__${process.env.hashProjectPath}"]` +
|
||||
` && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__${process.env.hashProjectPath}"])` +
|
||||
`.indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__${process.env.hashProjectPath}"]` +
|
||||
`[moduleId] = module;\n}`);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -33,7 +33,8 @@ const {
|
||||
deleteFolderRecursive,
|
||||
readManifest,
|
||||
loadEntryObj,
|
||||
compileCardModule
|
||||
compileCardModule,
|
||||
hashProjectPath
|
||||
} = require('./main.product')
|
||||
|
||||
const richModule = {
|
||||
@@ -189,6 +190,7 @@ function setConfigs(env) {
|
||||
process.env.logLevel = env.logLevel || '1'
|
||||
process.env.isPreview = env.isPreview || false
|
||||
process.env.projectPath = env.aceModuleRoot || process.env.aceModuleRoot || process.cwd();
|
||||
hashProjectPath(process.env.projectPath);
|
||||
process.env.buildPath = env.aceModuleBuild || process.env.aceModuleBuild ||
|
||||
path.resolve(process.env.projectPath, 'build');
|
||||
process.env.cachePath = env.cachePath || process.env.cachePath || path.resolve(__dirname, 'node_modules/.cache');
|
||||
@@ -337,5 +339,6 @@ module.exports = (env) => {
|
||||
loader: path.resolve(__dirname, './index.js')
|
||||
}]
|
||||
})
|
||||
config.output.library = process.env.hashProjectPath;
|
||||
return config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user