GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(html): add `module.generator.html.extract` option by alexander-akait · Pull Request #20979 · webpack/webpack

feat(html): add module.generator.html.extract option #20979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
alexander-akait merged 11 commits into main from claude/html-extract-option-9Rwvz
May 19, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(html): add module.generator.html.extract option #20979

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
cb6337e
feat(html): add `module.generator.html.extract` option
alexander-akait May 18, 2026
37e9983
feat(html): move filename to output.htmlFilename / htmlChunkFilename
alexander-akait May 18, 2026
70370f4
feat(html): auto-extract HTML modules used as compilation entries
alexander-akait May 18, 2026
2485402
test(html): strip irrelevant config from extract test fixtures
alexander-akait May 18, 2026
13349e6
fix(html): address copilot review and rebase fallout
alexander-akait May 19, 2026
7d293cc
test(html): update CLI flags snapshot for new generator/output options
alexander-akait May 19, 2026
783c83f
fix(html): skip HotUpdateChunks in renderManifest
alexander-akait May 19, 2026
c3d79d7
feat(html): route <link rel="stylesheet"> in HTML through CSS pipeline
alexander-akait May 19, 2026
e47e770
fix(html): address copilot review on the entry-point-css commit
alexander-akait May 19, 2026
ecc8108
fix(html): address remaining copilot review and Validation snapshot
alexander-akait May 19, 2026
4b3a7e5
fix(html): include "stylesheet" in EntryScriptInfo typedef
alexander-akait May 19, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

9 changes: 9 additions & 0 deletions 9 .changeset/html-extract-option.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"webpack": minor
---

Add `module.generator.html.extract` for HTML modules and the matching `output.htmlFilename` / `output.htmlChunkFilename` filename templates (defaults derived from `output.filename` / `output.chunkFilename` with `.js` swapped for `.html`, mirroring the CSS pipeline). When extraction is on, the parsed and URL-rewritten HTML is emitted as a standalone `.html` output file alongside the module's JavaScript export.
Comment thread

When `extract` is left unset, it defaults to `true` for HTML modules used as compilation entries (HTML entry points) and to `false` for HTML modules imported from JavaScript — so `entry: "./page.html"` just works.

Also fix `<script src>` / `<link rel="modulepreload">` references inside HTML modules to load every chunk in the referenced entry — including runtime chunks split off by `optimization.runtimeChunk` and shared chunks created by `optimization.splitChunks` — instead of only the entry chunk.
1 change: 1 addition & 0 deletions 1 cspell.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"reexecuted",
"referenceable",
"referencer",
"referrerpolicy",
"reparsed",
"reparsing",
"repo",
Expand Down
37 changes: 37 additions & 0 deletions 37 declarations/WebpackOptions.d.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ export type HotUpdateGlobal = string;
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
export type HotUpdateMainFilename = string;
/**
* Specifies the filename template of non-initial output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type HtmlChunkFilename = FilenameTemplate;
/**
* Specifies the filename template of output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type HtmlFilename = FilenameTemplate;
/**
* Wrap javascript code into IIFE's to avoid leaking into global scope.
*/
Expand Down Expand Up @@ -2431,6 +2439,14 @@ export interface Output {
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: HotUpdateMainFilename;
/**
* Specifies the filename template of non-initial output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
htmlChunkFilename?: HtmlChunkFilename;
/**
* Specifies the filename template of output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
htmlFilename?: HtmlFilename;
/**
* Ignore warnings in the browser.
*/
Expand Down Expand Up @@ -3476,6 +3492,15 @@ export interface ExperimentsNormalized {
*/
typescript?: boolean;
}
/**
* Generator options for html modules.
*/
export interface HtmlGeneratorOptions {
/**
* Emit the parsed and URL-rewritten HTML as a standalone `.html` output file alongside the module's JavaScript export. When unset, extraction defaults to `true` for HTML modules used as compilation entries (HTML entry points) and `false` for HTML modules imported from JavaScript. Filenames follow `output.htmlFilename` / `output.htmlChunkFilename`.
*/
extract?: boolean;
}
/**
* Parser options for javascript modules.
*/
Expand Down Expand Up @@ -3942,6 +3967,14 @@ export interface OutputNormalized {
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: HotUpdateMainFilename;
/**
* Specifies the filename template of non-initial output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
htmlChunkFilename?: HtmlChunkFilename;
/**
* Specifies the filename template of output html files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
htmlFilename?: HtmlFilename;
/**
* Ignore warnings in the browser.
*/
Expand Down Expand Up @@ -4236,6 +4269,10 @@ export interface GeneratorOptionsByModuleTypeKnown {
* Generator options for css/module modules.
*/
"css/module"?: CssModuleGeneratorOptions;
/**
* Generator options for html modules.
*/
html?: HtmlGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
Expand Down
47 changes: 47 additions & 0 deletions 47 lib/config/defaults.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,16 @@ const applyModuleDefaults = (
}
}

if (html) {
// `module.generator.html.extract` is intentionally left undefined by
// default: HtmlGenerator treats undefined as "extract iff this HTML
// module is a compilation entry", which is the HTML-entry-point
// behaviour. Setting `extract: true` forces extraction for all HTML
// modules (including imported ones); `extract: false` disables it
// everywhere.
F(module.generator, HTML_MODULE_TYPE, () => ({}));
}

A(module, "defaultRules", () => {
const esm = {
type: JAVASCRIPT_MODULE_TYPE_ESM,
Expand Down Expand Up @@ -1572,6 +1582,43 @@ const applyOutputDefaults = (
}
return "[id].css";
});
// Derive html filename defaults from `output.filename` / `output.chunkFilename`
// (the same shape the CSS pipeline uses), but if the derived template lacks
// any per-module differentiator, fall back to `[name].html` so multiple
// extracted HTML modules in one compilation don't collide on the same
// emitted file. For example: `output.filename: "bundle.js"` would derive
// `bundle.html` — two `.html` modules extracted in the same build would
// both want that name and conflict at emit time.
const HAS_PATH_PLACEHOLDER_REGEXP =
/\[(name|id|chunkhash|contenthash|fullhash|hash)/;
/**
* @param {string} template html filename template derived from `output.filename`
* @returns {string} same template, or `[name].html` if it has no per-module placeholder
*/
const ensureUniqueHtmlTemplate = (template) =>
HAS_PATH_PLACEHOLDER_REGEXP.test(template) ? template : "[name].html";
F(output, "htmlFilename", () => {
const filename =
/** @type {NonNullable<Output["htmlFilename"]>} */
(output.filename);
if (typeof filename !== "function") {
return ensureUniqueHtmlTemplate(
filename.replace(/\.[mc]?js(\?|$)/, ".html$1")
);
}
return "[name].html";
});
F(output, "htmlChunkFilename", () => {
const chunkFilename =
/** @type {NonNullable<Output["htmlChunkFilename"]>} */
(output.chunkFilename);
if (typeof chunkFilename !== "function") {
return ensureUniqueHtmlTemplate(
chunkFilename.replace(/\.[mc]?js(\?|$)/, ".html$1")
);
}
return "[name].html";
});
D(output, "assetModuleFilename", "[hash][ext][query][fragment]");
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
D(output, "compareBeforeEmit", true);
Expand Down
2 changes: 2 additions & 0 deletions 2 lib/config/normalization.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ const getNormalizedWebpackOptions = (config) => ({
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
hotUpdateGlobal: output.hotUpdateGlobal,
hotUpdateMainFilename: output.hotUpdateMainFilename,
htmlChunkFilename: output.htmlChunkFilename,
htmlFilename: output.htmlFilename,
ignoreBrowserWarnings: output.ignoreBrowserWarnings,
iife: output.iife,
importFunctionName: output.importFunctionName,
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.