Rspack 内置了对 JSON 的支持,你可以直接导入 JSON 文件。
{
"foo": "bar"
}import json from './example.json';
console.log(json.foo); // "bar"在非 .mjs 的非严格 ESM 文件中,你可以直接导入 JSON 中的属性。
{
"foo": "bar"
}import { foo } from './example.json';
console.log(foo); // "bar"Rspack 支持 import attributes,你可以通过 import attributes 来引入 JSON:
import json from './example.json' with { type: 'json' };
import('./example.json', { with: { type: 'json' } });