visual-studio-codeliveserver

How can Live Server in VS Code serve HTML files with other file extensions?


In a VS Code project I have HTML files which end in the (proprietary) extension .HML. How can Live Server in VS Code serve these files as HTML files?

I have seen starball's answer to "Why is VS Code Live Server opening...". It explains how some explicit files without .html extension can be served by Live Server, but I am after a solution which can serve all .hml files the same way as Live Server already saves all .html files.


Solution

  • Since mime type header is apparently the issue, I think you're out of luck unless you feel like forking the software or modifying your extension's installation. The Live Server extension uses the send npm package to serve static files. send uses the mime npm package, which only maps html, htm, and shtml to the text/html mime type.

    I haven't tried this, but I think you could technically dig into your ~/.vscode/extensions/ritwickdey.liveserver-<version>//node_modules/mime/types.json and edit the file to add the extension you want, but you'd need to redo this every time the extension updates.

    Even then, it won't be exactly the same as how files with the .html extension in their name are served, since send special-cases the filename index.html. Again, if you want a different behaviour, you'll need to fork or modify your installation.