From f72b803ed635e3b4a0c587c53e170e7cc922b1ce Mon Sep 17 00:00:00 2001 From: Naveen Jain Date: Tue, 30 Jul 2019 23:05:44 +0530 Subject: [PATCH 1/2] Fixed automaticPrefetchPlugin to not apply loaders via config to the requests --- lib/AutomaticPrefetchPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AutomaticPrefetchPlugin.js b/lib/AutomaticPrefetchPlugin.js index 84c76aa795d..7948276ce6f 100644 --- a/lib/AutomaticPrefetchPlugin.js +++ b/lib/AutomaticPrefetchPlugin.js @@ -45,7 +45,7 @@ class AutomaticPrefetchPlugin { (m, callback) => { compilation.addModuleChain( m.context || compiler.context, - new PrefetchDependency(m.request), + new PrefetchDependency(`!!${m.request}`), callback ); }, From 684d3755418763cc2f671635f5d1de8d41c9afd0 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 13 Jan 2021 12:45:22 +0100 Subject: [PATCH 2/2] add test case --- .../automatic-prefetch-plugin-9485/0/delayed.js | 1 + .../automatic-prefetch-plugin-9485/0/foo/0.js | 1 + .../automatic-prefetch-plugin-9485/0/foo/a.js | 1 + .../automatic-prefetch-plugin-9485/0/foo/b.js | 1 + .../automatic-prefetch-plugin-9485/0/foo/c.js | 1 + .../automatic-prefetch-plugin-9485/0/index.js | 10 ++++++++++ .../automatic-prefetch-plugin-9485/1/foo/1.js | 1 + .../automatic-prefetch-plugin-9485/2/foo/2.js | 1 + .../automatic-prefetch-plugin-9485/3/foo/3.js | 5 +++++ .../automatic-prefetch-plugin-9485/delayed.js | 9 +++++++++ .../webpack.config.js | 15 +++++++++++++++ 11 files changed, 46 insertions(+) create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/delayed.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/0.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/a.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/b.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/c.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/0/index.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/1/foo/1.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/2/foo/2.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/3/foo/3.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/delayed.js create mode 100644 test/watchCases/plugins/automatic-prefetch-plugin-9485/webpack.config.js diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/delayed.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/delayed.js new file mode 100644 index 00000000000..0696fcd6ae0 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/delayed.js @@ -0,0 +1 @@ +})] diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/0.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/0.js new file mode 100644 index 00000000000..61dfec6b18a --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/0.js @@ -0,0 +1 @@ +module.exports = '0'; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/a.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/a.js new file mode 100644 index 00000000000..252028035af --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/a.js @@ -0,0 +1 @@ +module.exports = "This "; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/b.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/b.js new file mode 100644 index 00000000000..14485a976a2 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/b.js @@ -0,0 +1 @@ +module.exports = "is only "; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/c.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/c.js new file mode 100644 index 00000000000..910a0111794 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/foo/c.js @@ -0,0 +1 @@ +module.exports = "a test"; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/index.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/index.js new file mode 100644 index 00000000000..da329579cd1 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/0/index.js @@ -0,0 +1,10 @@ +it("should watch for changes", function () { + if (+WATCH_STEP !== 3) expect(require("./delayed")).toBe(WATCH_STEP); + else expect(require("./delayed")).toBe("This is only a test." + WATCH_STEP); + if (+WATCH_STEP > 0) { + for (var m of STATS_JSON.modules.filter(m => + /(a|b|c)\.js$/.test(m.identifier) + )) + expect(m.issuer).toBe(null); + } +}); diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/1/foo/1.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/1/foo/1.js new file mode 100644 index 00000000000..4ac32c71327 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/1/foo/1.js @@ -0,0 +1 @@ +module.exports = '1'; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/2/foo/2.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/2/foo/2.js new file mode 100644 index 00000000000..2db2c90b9d6 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/2/foo/2.js @@ -0,0 +1 @@ +module.exports = '2'; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/3/foo/3.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/3/foo/3.js new file mode 100644 index 00000000000..63e585f4129 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/3/foo/3.js @@ -0,0 +1,5 @@ +var a = require("./a"); +var b = require("./b"); +var c = require("./c"); + +module.exports = a + b + c + '.3'; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/delayed.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/delayed.js new file mode 100644 index 00000000000..9c95b9ad3ba --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/delayed.js @@ -0,0 +1,9 @@ +module.exports = function (source) { + expect(source).toMatch(/^\}\)\]/); + this.cacheable(false); + return new Promise(resolve => { + setTimeout(() => { + resolve("module.exports = require('./foo/' + WATCH_STEP);"); + }, 500); + }); +}; diff --git a/test/watchCases/plugins/automatic-prefetch-plugin-9485/webpack.config.js b/test/watchCases/plugins/automatic-prefetch-plugin-9485/webpack.config.js new file mode 100644 index 00000000000..cfc6b797db9 --- /dev/null +++ b/test/watchCases/plugins/automatic-prefetch-plugin-9485/webpack.config.js @@ -0,0 +1,15 @@ +const path = require("path"); +const webpack = require("../../../../"); + +/** @type {import("../../../../").Configuration} */ +module.exports = { + module: { + rules: [ + { + test: /delayed/, + use: path.resolve(__dirname, "./delayed") + } + ] + }, + plugins: [new webpack.AutomaticPrefetchPlugin()] +};