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/Hq64iapoQXHbYMEN/icons/typescript.svg?fit=max&auto=format&n=Hq64iapoQXHbYMEN&q=85&s=c6cceedec8f82d2cc803d7c6ec82b240file.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. This feature was added in Bun v1.1.5.