diff --git a/lib/Compilation.js b/lib/Compilation.js index da0e14fa9..9f2da7218 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -2287,11 +2287,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.hooks.failedEntry.call(entry, options, err); return callback(err); } - this.hooks.succeedEntry.call( - entry, - options, - /** @type {Module} */ (module) - ); + this.hooks.succeedEntry.call(entry, options, module); return callback(null, module); } ); diff --git a/lib/IgnorePlugin.js b/lib/IgnorePlugin.js index 8d6bb619e..8049ac129 100644 --- a/lib/IgnorePlugin.js +++ b/lib/IgnorePlugin.js @@ -5,6 +5,8 @@ "use strict"; +const RawModule = require("./RawModule"); +const EntryDependency = require("./dependencies/EntryDependency"); const createSchemaValidation = require("./util/create-schema-validation"); /** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */ @@ -73,7 +75,23 @@ class IgnorePlugin { */ apply(compiler) { compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => { - nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore); + nmf.hooks.beforeResolve.tap("IgnorePlugin", resolveData => { + const result = this.checkIgnore(resolveData); + + if ( + result === false && + resolveData.dependencies.length > 0 && + resolveData.dependencies[0] instanceof EntryDependency + ) { + resolveData.ignoredModule = new RawModule( + "", + "ignored-entry-module", + "(ignored-entry-module)" + ); + } + + return result; + }); }); compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => { cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore); diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 6b3c0a93a..75a8b14d6 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -68,6 +68,7 @@ const { * @property {LazySet} fileDependencies * @property {LazySet} missingDependencies * @property {LazySet} contextDependencies + * @property {Module=} ignoredModule * @property {boolean} cacheable allow to use the unsafe cache */ @@ -885,12 +886,19 @@ class NormalModuleFactory extends ModuleFactory { // Ignored if (result === false) { - return callback(null, { + /** @type {ModuleFactoryResult} * */ + const factoryResult = { fileDependencies, missingDependencies, contextDependencies, cacheable: resolveData.cacheable - }); + }; + + if (resolveData.ignoredModule) { + factoryResult.module = resolveData.ignoredModule; + } + + return callback(null, factoryResult); } if (typeof result === "object") @@ -911,6 +919,7 @@ class NormalModuleFactory extends ModuleFactory { }); } + /** @type {ModuleFactoryResult} * */ const factoryResult = { module, fileDependencies, diff --git a/lib/javascript/JavascriptModulesPlugin.js b/lib/javascript/JavascriptModulesPlugin.js index 045e2a4ca..49409dd7e 100644 --- a/lib/javascript/JavascriptModulesPlugin.js +++ b/lib/javascript/JavascriptModulesPlugin.js @@ -83,7 +83,7 @@ const chunkHasJs = (chunk, chunkGraph) => { * @param {ChunkGraph} chunkGraph the chunk graph * @returns {boolean} true, when a JS file is needed for this chunk */ -const chunkHasJsOrRuntime = (chunk, chunkGraph) => { +const chunkHasRuntimeOrJs = (chunk, chunkGraph) => { if ( chunkGraph.getChunkModulesIterableBySourceType( chunk, @@ -313,7 +313,7 @@ class JavascriptModulesPlugin { hooks ); } else if (chunk.hasRuntime()) { - if (!chunkHasJsOrRuntime(chunk, chunkGraph)) { + if (!chunkHasRuntimeOrJs(chunk, chunkGraph)) { return result; } diff --git a/test/configCases/errors/multi-entry-missing-module/test.config.js b/test/configCases/errors/multi-entry-missing-module/test.config.js index 7a28872b5..0bf2100df 100644 --- a/test/configCases/errors/multi-entry-missing-module/test.config.js +++ b/test/configCases/errors/multi-entry-missing-module/test.config.js @@ -1,10 +1,5 @@ module.exports = { findBundle: function () { - return [ - // TODO improve me? - // "./a.js", - // "./b.js", - "./bundle0.js" - ]; + return ["./a.js", "./b.js", "./bundle0.js"]; } }; diff --git a/types.d.ts b/types.d.ts index 847e7450a..e04fe42c2 100644 --- a/types.d.ts +++ b/types.d.ts @@ -11929,6 +11929,7 @@ declare interface ResolveData { fileDependencies: LazySet; missingDependencies: LazySet; contextDependencies: LazySet; + ignoredModule?: Module; /** * allow to use the unsafe cache