Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions test/configCases/records/with-readRecords-hook/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "vendor";
3 changes: 3 additions & 0 deletions test/configCases/records/with-readRecords-hook/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should load fine", () => {
return import(/* webpackChunkName: "async" */"./async");
});
Empty file.
10 changes: 10 additions & 0 deletions test/configCases/records/with-readRecords-hook/records.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"chunks": {
"byName": {
"vendors~async": 123
},
"bySource": {
"1 index.js ./async": 123
}
}
}
17 changes: 17 additions & 0 deletions test/configCases/records/with-readRecords-hook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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
}
}
};