Bun prend nativement en charge les importations .json.
json
{
"name": "bun",
"version": "1.0.0",
"author": {
"name": "John Dough",
"email": "john@dough.com"
}
}Importez le fichier comme n'importe quel autre fichier source.
ts
import data from "./package.json";
data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"Bun prend également en charge la syntaxe des attributs d'importation et des modules JSON.
ts
import data from "./package.json" with { type: "json" };
data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"Consultez Docs > Runtime > TypeScript pour plus d'informations sur l'utilisation de TypeScript avec Bun.