Skip to content

Commit 18ca275

Browse files
Add support for using .htm instead of .html files
1 parent 7e569dd commit 18ca275

File tree

13 files changed

+54
-7
lines changed

13 files changed

+54
-7
lines changed

packages/nomodule-plugin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function nomodulePlugin({} = {}) {
3232
// Update all the HTML files with <script type=module> to add legacy loading via Shimport+Polyfills
3333
for (const fileName in bundle) {
3434
const asset = bundle[fileName];
35-
if (asset.type !== 'asset' || typeof asset.source !== 'string' || !asset.fileName.match(/\.html$/)) continue;
35+
if (asset.type !== 'asset' || typeof asset.source !== 'string' || !asset.fileName.match(/\.html?$/)) continue;
3636
if (!/<script(?:\s[^>]*)?\s+type=(['"])module\1/.test(asset.source)) continue;
3737
// this is gross obviously
3838
const POLYFILL = 'https://unpkg.com/@babel/[email protected]/browser.js'; // https://unpkg.com/regenerator-runtime

packages/wmr/src/lib/output-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function scoreAsset(asset) {
3535
return asset.isEntry ? 10 : asset.isDynamicEntry ? 8 : 6;
3636
}
3737
// List HTML files first, sorted by path depth
38-
if (/\.html$/.test(asset.fileName)) {
38+
if (/\.html?$/.test(asset.fileName)) {
3939
return 30 - asset.fileName.split('/').length;
4040
}
4141
return 1;

packages/wmr/src/plugins/html-entries-plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function htmlEntriesPlugin({ cwd, publicDir, publicPath } = {}) {
3434

3535
/** @this {import('rollup').PluginContext} */
3636
async function handleHtmlEntry(id) {
37-
if (!/\.html$/.test(id)) return id;
37+
if (!/\.html?$/.test(id)) return id;
3838

3939
this.addWatchFile(id);
4040
const resolved = await this.resolve(id, undefined, { skipSelf: true });
@@ -131,7 +131,7 @@ export default function htmlEntriesPlugin({ cwd, publicDir, publicPath } = {}) {
131131
const scripts = await Promise.all(entries.map(handleHtmlEntry.bind(this)));
132132
opts.input = scripts.flat();
133133
if (opts.input.length === 0) {
134-
const htmlEntries = entries.filter(id => /\.html$/.test(id));
134+
const htmlEntries = entries.filter(id => /\.html?$/.test(id));
135135

136136
let desc = htmlEntries.slice(0, 3).join(', ');
137137
if (htmlEntries.length > 3) desc += ` (+${htmlEntries.length - 3} more)`;
@@ -146,7 +146,7 @@ export default function htmlEntriesPlugin({ cwd, publicDir, publicPath } = {}) {
146146
async generateBundle(_, bundle) {
147147
for (const id in bundle) {
148148
const thisAsset = bundle[id];
149-
if (thisAsset.type !== 'asset' || !/\.html$/.test(thisAsset.fileName)) continue;
149+
if (thisAsset.type !== 'asset' || !/\.html?$/.test(thisAsset.fileName)) continue;
150150

151151
/** @type {ExtendedAsset} */
152152
const htmlAsset = Object.assign(thisAsset, {

packages/wmr/src/plugins/optimize-graph-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function hoistEntryCss(graph) {
252252
for (const fileName in graph.bundle) {
253253
/** @type {ExtendedAsset | Chunk} */
254254
const asset = graph.bundle[fileName];
255-
if (asset.type !== 'asset' || !/\.html$/.test(fileName)) continue;
255+
if (asset.type !== 'asset' || !/\.html?$/.test(fileName)) continue;
256256

257257
const cssImport = asset.referencedFiles && asset.referencedFiles.find(f => f.endsWith('.css'));
258258
if (!cssImport || !asset.importedIds) continue;

packages/wmr/src/plugins/wmr/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ connect();
2626

2727
let errorCount = 0;
2828

29-
const URL_SUFFIX = /\/(index\.html)?$/;
29+
const URL_SUFFIX = /\/(index\.html?)?$/;
3030

3131
function handleMessage(e) {
3232
const data = JSON.parse(e.data);

packages/wmr/test/fixtures.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ describe('fixtures', () => {
6969
});
7070
});
7171

72+
it('should work with .htm extension', async () => {
73+
await loadFixture('htm-index', env);
74+
instance = await runWmrFast(env.tmp.path);
75+
await waitForNotMessage(instance.output, `missing an "index.html"`);
76+
expect(await getOutput(env, instance)).toMatch(`<h1>foo</h1>`);
77+
});
78+
7279
describe('empty', () => {
7380
it('should print warning for missing index.html file in public dir', async () => {
7481
await loadFixture('empty', env);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<body>
4+
<h1>Hello wmr</h1>
5+
<script src="./index.js" type="module"></script>
6+
</body>
7+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { foo } from './foo.js';
2+
3+
document.querySelector('h1').textContent = foo;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';

0 commit comments

Comments
 (0)