diff --git a/declarations/WebpackOptions.d.ts b/declarations/WebpackOptions.d.ts index 66f43134d..5fc44cedc 100644 --- a/declarations/WebpackOptions.d.ts +++ b/declarations/WebpackOptions.d.ts @@ -1180,6 +1180,10 @@ export interface OutputOptions { * Number of milliseconds before chunk request expires */ chunkLoadTimeout?: number; + /** + * Check if to be emitted file already exists and have the same content before writing to output filesystem + */ + compareBeforeEmit?: boolean; /** * This option enables cross-origin loading of chunks. */ diff --git a/lib/Compiler.js b/lib/Compiler.js index 8ad422d05..2c9d4b43e 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -581,15 +581,19 @@ class Compiler { } } - this.outputFileSystem.stat(targetPath, (err, stats) => { - const exists = !err && stats.isFile(); + if (this.options.output.compareBeforeEmit) { + this.outputFileSystem.stat(targetPath, (err, stats) => { + const exists = !err && stats.isFile(); - if (exists) { - processExistingFile(stats); - } else { - processMissingFile(); - } - }); + if (exists) { + processExistingFile(stats); + } else { + processMissingFile(); + } + }); + } else { + processMissingFile(); + } }; if (targetFile.match(/\/|\\/)) { diff --git a/lib/WebpackOptionsDefaulter.js b/lib/WebpackOptionsDefaulter.js index 624eec458..f559314f6 100644 --- a/lib/WebpackOptionsDefaulter.js +++ b/lib/WebpackOptionsDefaulter.js @@ -232,6 +232,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter { this.set("output.webassemblyModuleFilename", "[hash].module.wasm"); this.set("output.library", ""); this.set("output.publicPath", ""); + this.set("output.compareBeforeEmit", true); this.set("output.hotUpdateFunction", "make", options => { return Template.toIdentifier( "webpackHotUpdate" + Template.toIdentifier(options.output.library) diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index cc522a8d3..e8d0506cd 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -1123,6 +1123,10 @@ "description": "Number of milliseconds before chunk request expires", "type": "number" }, + "compareBeforeEmit": { + "description": "Check if to be emitted file already exists and have the same content before writing to output filesystem", + "type": "boolean" + }, "crossOriginLoading": { "description": "This option enables cross-origin loading of chunks.", "enum": [false, "anonymous", "use-credentials"]