From d011d862261cbb78a7127e44199fbe6972875c46 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 8 Apr 2023 09:43:00 +0530 Subject: [PATCH] test: add a case for readRecords hook usage --- .../with-readRecords-hook/ReadRecordsPlugin.js | 12 ++++++++++++ .../records/with-readRecords-hook/async.js | 1 + .../records/with-readRecords-hook/index.js | 3 +++ .../node_modules/vendor.js | 0 .../records/with-readRecords-hook/records.json | 10 ++++++++++ .../with-readRecords-hook/webpack.config.js | 17 +++++++++++++++++ 6 files changed, 43 insertions(+) create mode 100644 test/configCases/records/with-readRecords-hook/ReadRecordsPlugin.js create mode 100644 test/configCases/records/with-readRecords-hook/async.js create mode 100644 test/configCases/records/with-readRecords-hook/index.js create mode 100644 test/configCases/records/with-readRecords-hook/node_modules/vendor.js create mode 100644 test/configCases/records/with-readRecords-hook/records.json create mode 100644 test/configCases/records/with-readRecords-hook/webpack.config.js 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 + } + } +};