Skip to content

Commit f93ec13

Browse files
fix(html): hoist HtmlModulesPlugin requires out of the compilation hook
Enabling `experiments.html` by default applies HtmlModulesPlugin to every build. Its lazy `require`s inside the newCompilation hook crashed a watch rebuild that raced after Jest teardown; hoisting them to module scope fixes that and avoids re-requiring per compilation. Keep the no-loader Errors case opted out of the html experiment so it still exercises that path.
1 parent 029c667 commit f93ec13

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎lib/html/HtmlModulesPlugin.js‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ const HtmlInlineStyleDependency = require("../dependencies/HtmlInlineStyleDepend
2020
const HtmlSourceDependency = require("../dependencies/HtmlSourceDependency");
2121
const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
2222
const WebpackError = require("../errors/WebpackError");
23+
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
2324
const { compareModulesByFullName } = require("../util/comparators");
2425
const createHash = require("../util/createHash");
26+
const { getUndoPath, makePathsRelative } = require("../util/identifier");
2527
const { digestNonNumericOnly } = require("../util/nonNumericOnlyHash");
28+
const {
29+
PUBLIC_PATH_AUTO: autoPlaceholder
30+
} = require("../util/publicPathPlaceholder");
2631
const removeBOM = require("../util/removeBOM");
2732
const HtmlGenerator = require("./HtmlGenerator");
2833
const HtmlModule = require("./HtmlModule");
@@ -555,13 +560,6 @@ class HtmlModulesPlugin {
555560
// template's `[contenthash]` placeholder works; the
556561
// compilation hash is also forwarded so `[fullhash]` /
557562
// `[hash]` work in user-supplied templates.
558-
const {
559-
getUndoPath,
560-
makePathsRelative
561-
} = require("../util/identifier");
562-
const {
563-
PUBLIC_PATH_AUTO: autoPlaceholder
564-
} = require("../util/publicPathPlaceholder");
565563

566564
// Sentinel-resolved content and its content hash depend only on
567565
// the HTML-type module source — not on the chunk or output
@@ -765,8 +763,6 @@ class HtmlModulesPlugin {
765763

766764
// Resolve sentinels at JS chunk render time so later passes
767765
// (SourceMapDevToolPlugin, size optimizers, RealContentHash) see resolved bytes.
768-
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
769-
770766
const jsHooks =
771767
JavascriptModulesPlugin.getCompilationHooks(compilation);
772768
jsHooks.render.tap(PLUGIN_NAME, (source, renderContext) => {

‎test/Errors.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ describe("Loaders", () => {
874874
compile({
875875
mode: "development",
876876
entry: "./abc.html",
877+
// Opt out so `.html` stays unhandled and still hits the no-loader path.
878+
experiments: { css: false, html: false },
877879
module: {}
878880
})
879881
).resolves.toMatchInlineSnapshot(`

0 commit comments

Comments
 (0)