JSON
JSON 在 Rspack 中是一等公民。您可以直接匯入它,例如
預設匯入
index.js
import json from './example.json';
console.log(json.foo); // "bar"
具名匯入
在非 .mjs
的非嚴格 ESM 檔案中,您可以直接從 JSON 匯入屬性。
index.js
import { foo } from './example.json';
console.log(foo); // "bar"
匯入屬性
Rspack 支援匯入屬性,您可以使用匯入屬性來匯入 JSON
index.js
import json from './example.json' with { type: 'json' };
import('./example.json', { with: { type: 'json' } });