Files
bun.sh/docs/guides/runtime/import-html.md
Jarred Sumner 024c274a3d Support type import attribute with "text", "json", "toml", and "file" (#10456)
* Fixes #3449

Fixes https://github.com/oven-sh/bun/issues/10206
Fixes https://github.com/oven-sh/bun/issues/5710

* Apply formatting changes

* Update loaders.md

* Update text-loader-fixture-import.ts

* Add guide

* Update bundler_loader.test.ts

* Address comment

---------

Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-04-23 15:35:34 -07:00

435 B

name
name
Import 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.

This feature was added in Bun v1.1.5.