diff --git a/lib/Compiler.js b/lib/Compiler.js index 2d59a1a6481..ee8769f8254 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -970,10 +970,13 @@ ${other}`); readRecords(callback) { if (this.hooks.readRecords.isUsed()) { if (this.recordsInputPath) { - asyncLib.parallel([ - cb => this.hooks.readRecords.callAsync(cb), - this._readRecords.bind(this) - ]); + asyncLib.parallel( + [ + cb => this.hooks.readRecords.callAsync(cb), + this._readRecords.bind(this) + ], + err => callback(err) + ); } else { this.records = {}; this.hooks.readRecords.callAsync(callback); diff --git a/test/configCases/records/with-readRecords-hook/ReadRecordsPlugin.js b/test/configCases/records/with-readRecords-hook/ReadRecordsPlugin.js new file mode 100644 index 00000000000..4b173a8dca5 --- /dev/null +++ b/test/configCases/records/with-readRecords-hook/ReadRecordsPlugin.js @@ -0,0 +1,12 @@ +class ReadRecordsPlugin { + apply(compiler) { + compiler.hooks.readRecords.tapAsync("ReadRecordsPlugin", callback => { + setTimeout(() => { + console.log("Done with reading records."); + callback(); + }, 1000); + }); + } +} + +module.exports = ReadRecordsPlugin; diff --git a/test/configCases/records/with-readRecords-hook/async.js b/test/configCases/records/with-readRecords-hook/async.js new file mode 100644 index 00000000000..e08a1b185c2 --- /dev/null +++ b/test/configCases/records/with-readRecords-hook/async.js @@ -0,0 +1 @@ +import "vendor"; diff --git a/test/configCases/records/with-readRecords-hook/index.js b/test/configCases/records/with-readRecords-hook/index.js new file mode 100644 index 00000000000..15c49532184 --- /dev/null +++ b/test/configCases/records/with-readRecords-hook/index.js @@ -0,0 +1,3 @@ +it("should load fine", () => { + return import(/* webpackChunkName: "async" */"./async"); +}); diff --git a/test/configCases/records/with-readRecords-hook/node_modules/vendor.js b/test/configCases/records/with-readRecords-hook/node_modules/vendor.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/configCases/records/with-readRecords-hook/records.json b/test/configCases/records/with-readRecords-hook/records.json new file mode 100644 index 00000000000..dcca409b109 --- /dev/null +++ b/test/configCases/records/with-readRecords-hook/records.json @@ -0,0 +1,10 @@ +{ + "chunks": { + "byName": { + "vendors~async": 123 + }, + "bySource": { + "1 index.js ./async": 123 + } + } +} diff --git a/test/configCases/records/with-readRecords-hook/webpack.config.js b/test/configCases/records/with-readRecords-hook/webpack.config.js new file mode 100644 index 00000000000..503a8506c34 --- /dev/null +++ b/test/configCases/records/with-readRecords-hook/webpack.config.js @@ -0,0 +1,17 @@ +const path = require("path"); +const ReadRecordsPlugin = require("./ReadRecordsPlugin"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + entry: "./index", + recordsInputPath: path.resolve(__dirname, "records.json"), + output: { + chunkFilename: "[name]-[chunkhash].js" + }, + plugins: [new ReadRecordsPlugin()], + optimization: { + splitChunks: { + minSize: 0 + } + } +};