Support parsing .htm as same as .html
See original GitHub issueDescription
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
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems there’s many places using
id.endsWith('.html')
. I think it makes sense to use thathtmlLangRE
.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-L126I guess
htmlFallbackMiddleware
will be a bit complicated but other parts won’t be so complicated.