Skip to content

Bun で .html ファイルをテキストファイルとしてインポートするには、import 文で type: "text" 属性を使用します。

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

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

これは、ホットモジュールリローディングやウォッチモードでも使用でき、./file.html ファイルが変更されるたびに Bun に再読み込みを強制できます。

Bun by www.bunjs.com.cn 編集