Skip to main content
To import a .html file in Bun as a text file, use the type: "text" attribute in the import statement.
https://mintcdn.com/bun-1dd33a4e-farm-a91c5779-shell-sandbox/CFA6Tagw86uhJFhY/icons/typescript.svg?fit=max&auto=format&n=CFA6Tagw86uhJFhY&q=85&s=b76cf0e4a2c188862bc272cae1c4e52ffile.ts
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.