Signed-off-by: lizhouze <lizhouze@huawei.com>
This commit is contained in:
lizhouze
2022-05-30 14:45:06 +08:00
parent 47a69df7b7
commit 407bc4c45d
3 changed files with 56 additions and 2 deletions
+31
View File
@@ -177,6 +177,36 @@ function filterWorker(workerPath) {
return /\.(ts|js)$/.test(workerPath);
}
function compareCache(cachePath) {
const entryFile = path.join(cachePath, 'entry.json');
const cssFile = process.env.watchCSSFiles;
let files = [];
if (fs.existsSync(cssFile)) {
const cssObject = JSON.parse(fs.readFileSync(cssFile));
if (cssObject['clear'] === true) {
deleteFolderRecursive(cachePath);
return;
}
Object.keys(cssObject).forEach(key => {
if (key !== 'entry') {
files.push(key);
}
})
}
if (fs.existsSync(entryFile)) {
files = files.concat(JSON.parse(fs.readFileSync(entryFile)));
}
for(let file of files) {
if (!fs.existsSync(file)) {
deleteFolderRecursive(cachePath);
break;
}
}
}
module.exports = {
deleteFolderRecursive: deleteFolderRecursive,
readManifest: readManifest,
@@ -186,4 +216,5 @@ module.exports = {
checkMultiResourceBuild: checkMultiResourceBuild,
multiResourceBuild: multiResourceBuild,
readWorkerFile: readWorkerFile,
compareCache: compareCache
};
+21
View File
@@ -55,9 +55,15 @@ class ResultStates {
const buildPath = this.options.build;
const commonPaths = new Set();
const i18nPaths = new Set();
const cachePath = path.resolve(process.env.cachePath, '.rich_cache');
const entryFile = path.join(cachePath, 'entry.json');
const entryPaths = new Set();
compiler.hooks.compilation.tap('toFindModule', (compilation) => {
compilation.hooks.buildModule.tap("findModule", (module) => {
if (module.resource && fs.existsSync(module.resource)) {
entryPaths.add(module.resource);
}
if (module.context.indexOf(process.env.projectPath) >= 0) {
return;
}
@@ -86,6 +92,7 @@ class ResultStates {
for (let i18nPath of i18nPaths) {
circularFile(i18nPath, path.resolve(buildPath, '../share/i18n'));
}
addCacheFiles(entryFile, cachePath, entryPaths);
});
compiler.hooks.done.tap('Result States', (stats) => {
@@ -154,6 +161,20 @@ class ResultStates {
}
}
function addCacheFiles(entryFile, cachePath, entryPaths) {
const entryArray = [];
if (fs.existsSync(entryFile)) {
const oldArray = JSON.parse(fs.readFileSync(entryFile));
oldArray.forEach(element => {
entryPaths.add(element);
})
} else if (!fs.existsSync(cachePath)) {
mkDir(cachePath);
}
entryArray.push(...entryPaths);
fs.writeFileSync(entryFile, JSON.stringify(entryArray));
}
const red = '\u001b[31m';
const yellow = '\u001b[33m';
const blue = '\u001b[34m';
+4 -2
View File
@@ -36,7 +36,8 @@ const {
compileCardModule,
hashProjectPath,
checkMultiResourceBuild,
readWorkerFile
readWorkerFile,
compareCache
} = require('./main.product')
const richModule = {
@@ -180,7 +181,7 @@ function setConfigs(env) {
process.env.DEVICE_LEVEL = env.DEVICE_LEVEL || process.env.DEVICE_LEVEL || 'rich';
process.env.aceModuleJsonPath = env.aceModuleJsonPath || process.env.aceModuleJsonPath;
process.env.aceProfilePath = env.aceProfilePath || process.env.aceProfilePath;
process.env.watchCSSFiles = process.env.watchCSSFiles || path.resolve(process.env.buildPath, 'preview_css.json');
process.env.watchCSSFiles = process.env.watchCSSFiles || path.resolve(process.env.cachePath, '.rich_cache', 'preview_css.json');
watchMode = (process.env.watchMode && process.env.watchMode === 'true') ||
(env.watchMode && env.watchMode === 'true') || false;
if (process.env.abilityType === 'page' || process.env.abilityType === 'form') {
@@ -252,6 +253,7 @@ function excludeWorker(workerFile, name) {
module.exports = (env) => {
setConfigs(env);
compareCache(path.resolve(process.env.cachePath, '.rich_cache'));
const workerFile = readWorkerFile();
if (process.env.compileMode === 'moduleJson') {
compileCardModule(env);