diff --git a/packages/wxa-cli/src/builder.js b/packages/wxa-cli/src/builder.js index 473402a4..a43f0150 100644 --- a/packages/wxa-cli/src/builder.js +++ b/packages/wxa-cli/src/builder.js @@ -123,11 +123,14 @@ class Builder { let changedDeps; try { this.schedule.$depPending.push(mdl); - + if (mdl.childNodes && mdl.childNodes.size) this.walkChildNodesTreeAndMark(mdl); await this.hooks.rebuildModule.promise(this.schedule, mdl); changedDeps = await this.schedule.$doDPA(); - await this.optimizeAndGenerate(changedDeps, cmd); + + let map = new Map(changedDeps.map((mdl)=>[mdl.src, mdl])); + + await this.optimizeAndGenerate(map, this.schedule.appConfigs, cmd); } catch (e) { logger.error('编译失败', e); } @@ -173,6 +176,15 @@ class Builder { process.on('SIGHUP', h); } + walkChildNodesTreeAndMark(mdl) { + // mark tree nodes as changed + mdl.childNodes.forEach((child)=>{ + child.color = color.CHANGED; + + if (child.childNodes && child.childNodes.size) this.walkChildNodesTreeAndMark(child); + }); + } + async build(cmd) { if (cmd.verbose) logger.info('WxaConfigs', this.wxaConfigs); diff --git a/packages/wxa-cli/src/schedule.js b/packages/wxa-cli/src/schedule.js index 0e4badf9..3af4be08 100644 --- a/packages/wxa-cli/src/schedule.js +++ b/packages/wxa-cli/src/schedule.js @@ -5,7 +5,7 @@ import globby from 'globby'; import debugPKG from 'debug'; import {SyncHook} from 'tapable'; -import {readFile, isFile} from './utils'; +import {readFile, isFile, getHash, getHashWithString} from './utils'; import bar from './helpers/progressBar'; import logger from './helpers/logger'; import COLOR from './const/color'; @@ -190,6 +190,7 @@ class Schedule { let oldPages = new Map(this.$pageArray.entries()); let newPages = this.addPageEntryPoint(); + newPages = new Map(newPages.map((page)=>[page.src, page])); this.cleanUpPages(newPages, oldPages); } @@ -285,6 +286,7 @@ class Schedule { // the amount of child output is decided by his parent module. // normally one, emit multi while child module is npm package. + // debugger; let child = { ...dep, color: COLOR.INIT, @@ -298,6 +300,16 @@ class Schedule { if (this.$indexOfModule.has(dep.src)) { let indexedModule = this.$indexOfModule.get(dep.src); + // check hash + child.hash = !child.isAbstract && child.content ? getHashWithString(child.content) : getHash(child.src); + + if (child.hash !== indexedModule.hash) { + // module changed, clean up mdl. + indexedModule.content = child.content; + indexedModule.code = void(0); + indexedModule.hash = child.hash; + } + // merge reference, cause the module is parsed if (indexedModule.reference instanceof Map) { indexedModule.reference.set(mdl.src, mdl); @@ -312,7 +324,7 @@ class Schedule { child = indexedModule; } - + // debugger; if (child.color !== COLOR.COMPILED) this.$depPending.push(child); if (child.color === COLOR.INIT) this.$indexOfModule.set(child.src, child); diff --git a/packages/wxa-cli/src/utils.js b/packages/wxa-cli/src/utils.js index e0b1d3d5..b92a03a6 100644 --- a/packages/wxa-cli/src/utils.js +++ b/packages/wxa-cli/src/utils.js @@ -145,3 +145,7 @@ export function getHash(filepath) { return content == null ? Date.now() : crypto.createHash('md5').update(content).digest('hex'); } + +export function getHashWithString(content) { + return content == null ? Date.now() : crypto.createHash('md5').update(content).digest('hex'); +}