Skip to content

Commit 169b511

Browse files
feat: resolve default ./src entry to index.html/index.css under experiments (#21039)
1 parent 1084607 commit 169b511

24 files changed

Lines changed: 348 additions & 42 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": minor
3+
---
4+
5+
Support `.html`/`.css` for the default `./src` entry under the html/css experiments.

declarations/WebpackOptions.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ export interface Experiments {
13501350
*/
13511351
futureDefaults?: boolean;
13521352
/**
1353-
* Enable experimental HTML support. This flag does not by itself make `.html` files usable directly as entry points without additional HTML handling.
1353+
* Enable HTML entry support. Treats `.html` files as a first-class module type so they can be used directly as entry points.
13541354
* @experimental
13551355
*/
13561356
html?: boolean;

lib/config/defaults.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
525525
css:
526526
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
527527
(options.experiments.css),
528+
html:
529+
/** @type {NonNullable<ExperimentsNormalized["html"]>} */
530+
(options.experiments.html),
528531
typescript:
529532
/** @type {NonNullable<ExperimentsNormalized["typescript"]>} */
530533
(options.experiments.typescript)
@@ -2146,6 +2149,7 @@ const applyOptimizationDefaults = (
21462149
* @param {TargetProperties | false} options.targetProperties target properties
21472150
* @param {Mode} options.mode mode
21482151
* @param {boolean} options.css is css enabled
2152+
* @param {boolean} options.html is html enabled
21492153
* @param {boolean} options.typescript is typescript enabled
21502154
* @returns {ResolveOptions} resolve options
21512155
*/
@@ -2155,6 +2159,7 @@ const getResolveDefaults = ({
21552159
targetProperties,
21562160
mode,
21572161
css,
2162+
html,
21582163
typescript
21592164
}) => {
21602165
/** @type {string[]} */
@@ -2174,6 +2179,13 @@ const getResolveDefaults = ({
21742179
? [".ts", ".js", ".json", ".wasm"]
21752180
: [".js", ".json", ".wasm"];
21762181

2182+
// HTML-first when enabled: `.html` outranks `.js`, `.css` is the last fallback.
2183+
const esmResolveExtensions = [
2184+
...(html ? [".html"] : []),
2185+
...jsExtensions,
2186+
...(css ? [".css"] : [])
2187+
];
2188+
21772189
const tp = targetProperties;
21782190
const browserField =
21792191
tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer));
@@ -2207,7 +2219,7 @@ const getResolveDefaults = ({
22072219
"module",
22082220
"..."
22092221
],
2210-
extensions: [...jsExtensions]
2222+
extensions: [...esmResolveExtensions]
22112223
});
22122224

22132225
/** @type {() => ResolveOptions} */

schemas/WebpackOptions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@
11421142
"experimental": true
11431143
},
11441144
"html": {
1145-
"description": "Enable experimental HTML support. This flag does not by itself make `.html` files usable directly as entry points without additional HTML handling.",
1145+
"description": "Enable HTML entry support. Treats `.html` files as a first-class module type so they can be used directly as entry points.",
11461146
"type": "boolean",
11471147
"experimental": true
11481148
},

0 commit comments

Comments
 (0)