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' } });