Bun unterstützt .json-Importe nativ.
json
{
"name": "bun",
"version": "1.0.0",
"author": {
"name": "John Dough",
"email": "john@dough.com"
}
}Importieren Sie die Datei wie jede andere Quelldatei.
ts
import data from "./package.json";
data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"Bun unterstützt auch die Import Attributes- und JSON modules-Syntax.
ts
import data from "./package.json" with { type: "json" };
data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"Siehe Docs > Runtime > TypeScript für weitere Informationen zur Verwendung von TypeScript mit Bun.