Skip to main content
要在 Bun 中将 .html 文件作为文本文件导入,请在导入语句中使用 type: "text" 属性。
https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217file.ts
import html from "./file.html" with { type: "text" };

console.log(html); // <!DOCTYPE html><html><head>...
这也可以与热模块重载和/或监听模式一起使用,以强制 Bun 在 ./file.html 文件更改时重新加载。