若要在 Bun 中將 .html
檔案匯入為文字檔,請在 import 語句中使用 type: "text"
屬性。
import html from "./file.html" with { type: "text" };
console.log(html); // <!DOCTYPE html><html><head>...
這也可以與熱模組重載和/或監看模式一起使用,以強制 Bun 在 ./file.html
檔案變更時重新載入。
此功能在 Bun v1.1.5 中新增。
若要在 Bun 中將 .html
檔案匯入為文字檔,請在 import 語句中使用 type: "text"
屬性。
import html from "./file.html" with { type: "text" };
console.log(html); // <!DOCTYPE html><html><head>...
這也可以與熱模組重載和/或監看模式一起使用,以強制 Bun 在 ./file.html
檔案變更時重新載入。
此功能在 Bun v1.1.5 中新增。
讀取檔案
執行階段
串流
將 ReadableStream 轉換為 Uint8Array
將 ReadableStream 轉換為 ArrayBuffer
將 Node.js Readable 轉換為 Uint8Array
工具程式