JSON

JSON はRspackでファーストクラスの存在です。直接インポートできます。例えば

デフォルトインポート

example.json
{
  "foo": "bar"
}
index.js
import json from './example.json';
console.log(json.foo); // "bar"

名前付きインポート

.mjs の非strict ESMファイルでは、JSONから直接プロパティをインポートできます。

example.json
{
  "foo": "bar"
}
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' } });