JSON 模块
🌐 JSON modules
稳定性: 1 - 实验性
JSON 文件可以通过 import 引用:
🌐 JSON files can be referenced by import:
import packageConfig from './package.json' assert { type: 'json' }; assert { type: 'json' } 语法是必须的;见 导入断言。
🌐 The assert { type: 'json' } syntax is mandatory; see Import Assertions.
导入的 JSON 只暴露了 default 导出。不支持命名导出。为了避免重复,会在 CommonJS 缓存中创建一个缓存项。如果 JSON 模块已从相同路径导入,CommonJS 会返回同一个对象。
🌐 The imported JSON only exposes a default export. There is no support for named
exports. A cache entry is created in the CommonJS cache to avoid duplication.
The same object is returned in CommonJS if the JSON module has already been
imported from the same path.