Bun Import a HTML file as text

Import a HTML file as text

jarle Updated

File contents

Import a HTML file as text

To import a .html file in Bun as a text file, use the type: "text" attribute in the import statement.

import html from "./file.html" with { type: "text" };

console.log(html); // <!DOCTYPE html><html><head>...

This can also be used with hot module reloading and/or watch mode to force Bun to reload whenever the ./file.html file changes.

jarle/bun-skills/tree/main/skills/bun-guides-runtime-import-html commit 378e367b1d

Frequently asked questions

npx skillmds@latest add jarle/bun-import-a-html-file-as-text