Bun

指南运行时

使用 Bun 将 HTML 文件导入为文本

要在 Bun 中将 .html 文件作为文本文件导入,请在导入语句中使用 type: "text" 属性。

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

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

这也可以与热模块重新加载和/或监视模式一起使用,以便在 ./file.html 文件更改时强制 Bun 重新加载。

此功能已在 Bun v1.1.5 中添加。