question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support parsing .htm as same as .html

See original GitHub issue

Description

We are currently working on a rebuild of our old website.
I included the .htm file in the build target for now, but the build failed with a Parse error.
.htm files are rendered correctly in most modern browsers.
According to RFC2854 and this IANA text, .html and .htm are commonly used HTML extensions and I believe they should be used in vite.

It is a small thing, but I think it will be useful.

Also, I found a regular expression in the HTML plugin file that seems to support .htm, but it is not actually supported.
If the suggestion in this Issue is not good, why is this regex in there?

Suggested solution

Actual works method

in node/plugins/html/ts:301

    async transform(html, id) {
      if (id.endsWith('.html')) {
        const relativeUrlPath = path.posix.relative(

to

    async transform(html, id) {
      if (id.endsWith('.html') || id.endsWith('.htm')) {
        const relativeUrlPath = path.posix.relative(

Alternative

No response

Additional context

Parse error I got:

> homepage@0.0.0 build T:\projects\vite-test
> vite build

vite v3.2.4 building for production...
✓ 0 modules transformed.
[vite:build-import-analysis] Parse error @:8:28
file: T:/projects/vite-test/src/pages/a.htm:8:27
 6:           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 7:     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8:     <title>Document</title>
                               ^
 9: </head>
10: <body>
error during build:
Error: Parse error @:8:28
    at parse$b (file:///T:/projects/vite-test/node_modules/.pnpm/vite@3.2.4/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:32642:355)
    at Object.transform (file:///T:/projects/vite-test/node_modules/.pnpm/vite@3.2.4/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:42081:27)
 ERROR  Command failed with exit code 1.

Validations

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Nov 20, 2022

It seems there’s many places using id.endsWith('.html'). I think it makes sense to use that htmlLangRE.

0reactions
sapphi-redcommented, Nov 21, 2022

Oh, I didn’t think of the SPA fallback. sirv already supports .htm. So in preview, index.htm currently works. https://github.com/vitejs/vite/blob/a03860f1320c0bff8e2b8b7fd0e1c42a7565e767/packages/vite/src/node/preview.ts#L115-L126

I guess htmlFallbackMiddleware will be a bit complicated but other parts won’t be so complicated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support parsing .htm as same as .html · Issue #10997 · vitejs/vite
I included the .htm file in the build target for now, but the build failed with a Parse error. .htm files are rendered...
Read more >
Can you provide examples of parsing HTML? - Stack Overflow
Nice, but I think you are missing the point of the question, the example is there so that the code will be similar,...
Read more >
Parsing HTML: a guide to select the right library
Parsing HTML. The goal of this article is helping you to find the right library to process HTML: we consider Java, C#, Python,...
Read more >
HTML parser class - metacpan.org
Objects of the HTML::Parser class will recognize markup and separate it from plain text (alias data content) in HTML documents. As different kinds...
Read more >
Parsing Html The Cthulhu Way - Coding Horror
You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found