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

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