From 8ffe827f353e665826293f163568066081e83dcb Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 2 Nov 2023 14:56:11 -0700 Subject: [PATCH] fix: clear webpack asset emit cache afterEmit Fix #126 --- webpack/private/webpack_worker.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/webpack/private/webpack_worker.js b/webpack/private/webpack_worker.js index c01592d..3eff1a2 100755 --- a/webpack/private/webpack_worker.js +++ b/webpack/private/webpack_worker.js @@ -83,6 +83,16 @@ class WebpackWorker extends WebpackCLI { console.error(options) this.compiler = await super.createCompiler(options, cb) this.options = options + + // The output directory will be cleaned between runs, webpack assumes the output directory will not be modified: + // Webpack5: https://github.com/webpack/webpack/blob/v5.36.2/lib/Compiler.js#L783-L788 + if (this.compiler._assetEmittingPreviousFiles) { + this.compiler.hooks.afterEmit.tap("rules_webpack", () => this.compiler._assetEmittingPreviousFiles.clear()) + } + // Webpack4: https://github.com/webpack/webpack/blob/v4.47.0/lib/Compiler.js#L393-L398 + if (this._assetEmittingSourceCache) { + this.compiler.hooks.afterEmit.tap("rules_webpack", () => this.compiler._assetEmittingSourceCache.clear()) + } } } }