From bc368c76119d75981b7d9153cd1c3c52c17dc564 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Sat, 22 Dec 2018 13:39:26 +0100 Subject: [PATCH] fixes #8538 --- lib/IgnorePlugin.js | 2 ++ .../multiple-with-externals/ignored-module1.js | 1 + .../multiple-with-externals/ignored-module2.js | 1 + .../multiple-with-externals/normal-module.js | 1 + .../ignore/multiple-with-externals/test.js | 18 ++++++++++++++++++ .../multiple-with-externals/webpack.config.js | 18 ++++++++++++++++++ 6 files changed, 41 insertions(+) create mode 100644 test/configCases/ignore/multiple-with-externals/ignored-module1.js create mode 100644 test/configCases/ignore/multiple-with-externals/ignored-module2.js create mode 100644 test/configCases/ignore/multiple-with-externals/normal-module.js create mode 100644 test/configCases/ignore/multiple-with-externals/test.js create mode 100644 test/configCases/ignore/multiple-with-externals/webpack.config.js diff --git a/lib/IgnorePlugin.js b/lib/IgnorePlugin.js index a90f7edea..cd824db2b 100644 --- a/lib/IgnorePlugin.js +++ b/lib/IgnorePlugin.js @@ -38,6 +38,8 @@ class IgnorePlugin { * @returns {TODO|null} returns result or null if result should be ignored */ checkIgnore(result) { + if (!result) return result; + if ( "checkResource" in this.options && this.options.checkResource && diff --git a/test/configCases/ignore/multiple-with-externals/ignored-module1.js b/test/configCases/ignore/multiple-with-externals/ignored-module1.js new file mode 100644 index 000000000..4e015a52c --- /dev/null +++ b/test/configCases/ignore/multiple-with-externals/ignored-module1.js @@ -0,0 +1 @@ +module.exports = "ignored"; diff --git a/test/configCases/ignore/multiple-with-externals/ignored-module2.js b/test/configCases/ignore/multiple-with-externals/ignored-module2.js new file mode 100644 index 000000000..4e015a52c --- /dev/null +++ b/test/configCases/ignore/multiple-with-externals/ignored-module2.js @@ -0,0 +1 @@ +module.exports = "ignored"; diff --git a/test/configCases/ignore/multiple-with-externals/normal-module.js b/test/configCases/ignore/multiple-with-externals/normal-module.js new file mode 100644 index 000000000..f5f8a087f --- /dev/null +++ b/test/configCases/ignore/multiple-with-externals/normal-module.js @@ -0,0 +1 @@ +module.exports = "normal"; diff --git a/test/configCases/ignore/multiple-with-externals/test.js b/test/configCases/ignore/multiple-with-externals/test.js new file mode 100644 index 000000000..caa14b2ab --- /dev/null +++ b/test/configCases/ignore/multiple-with-externals/test.js @@ -0,0 +1,18 @@ +/* globals it */ +"use strict"; + +it("should ignore ignored resources 1", function() { + expect(function() { + require("./ignored-module1"); + }).toThrowError(); +}); +it("should ignore ignored resources 2", function() { + expect(function() { + require("./ignored-module2"); + }).toThrowError(); +}); +it("should not ignore resources that do not match", function() { + expect(function() { + require("./normal-module"); + }).not.toThrowError(); +}); diff --git a/test/configCases/ignore/multiple-with-externals/webpack.config.js b/test/configCases/ignore/multiple-with-externals/webpack.config.js new file mode 100644 index 000000000..d1cc2d086 --- /dev/null +++ b/test/configCases/ignore/multiple-with-externals/webpack.config.js @@ -0,0 +1,18 @@ +"use strict"; + +const IgnorePlugin = require("../../../../lib/IgnorePlugin"); + +module.exports = { + entry: "./test.js", + externals: { + "./normal-module": "{}" + }, + plugins: [ + new IgnorePlugin({ + resourceRegExp: /ignored-module1/ + }), + new IgnorePlugin({ + resourceRegExp: /ignored-module2/ + }) + ] +};