From fc4f0813fa6884abb5c8b60d58b6e3a3e850b85c Mon Sep 17 00:00:00 2001 From: ming Date: Sat, 28 Mar 2020 16:48:53 -0700 Subject: [PATCH] prevent activation of module that are already compiled, remove initial activation --- lib/plugin.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index d961d26..f4330ab 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -60,9 +60,13 @@ class LazyCompilePlugin { } const moduleInfo = this._lazyModules.get(id); - if (moduleInfo) { + const status = moduleInfo.status; + if ( + moduleInfo && + (status === ModuleStatus.INIT || status === ModuleStatus.BLOCKED) + ) { moduleInfo.status = ModuleStatus.READY; - return this._recompile(moduleInfo.filename); + await this._recompile(moduleInfo.filename); } } @@ -92,8 +96,8 @@ class LazyCompilePlugin { } ); - compiler.hooks.compilation.tap('LazyCompilePlugin', compilation => { - compilation.hooks.buildModule.tap('LazyCompilePlugin', wpModule => { + compiler.hooks.compilation.tap('LazyCompilePlugin', (compilation) => { + compilation.hooks.buildModule.tap('LazyCompilePlugin', (wpModule) => { const id = getModuleId(wpModule); if (!this._lazyModules.has(id)) { return; @@ -126,10 +130,7 @@ class LazyCompilePlugin { }); }); - compiler.hooks.done.tap('LazyCompilePlugin', () => { - if (this._firstCompileDone) return; - - this._pendingActivation.forEach(id => this.activateModule(id)); + compiler.hooks.done.tapPromise('LazyCompilePlugin', async () => { this._firstCompileDone = true; }); } @@ -143,7 +144,7 @@ class LazyCompilePlugin { } async _recompile(filename) { - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { const now = new Date(); // trigger watcher to recompile