From 17a6cf8d73ad2d45607755b46fad5b456f545172 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Thu, 19 Jun 2025 16:16:29 +0800 Subject: [PATCH] docs: use import attributes to import JSON files --- website/docs/en/guide/advanced/json-files.mdx | 10 ++++++++++ website/docs/zh/guide/advanced/json-files.mdx | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/website/docs/en/guide/advanced/json-files.mdx b/website/docs/en/guide/advanced/json-files.mdx index b2c383ce8..7adfeb3cb 100644 --- a/website/docs/en/guide/advanced/json-files.mdx +++ b/website/docs/en/guide/advanced/json-files.mdx @@ -105,6 +105,16 @@ export { __webpack_exports__items as items, __webpack_exports__name as name }; +### Use import attributes + +In bundle mode, Rslib supports [import attributes](https://github.com/tc39/proposal-import-attributes), and you can import JSON files through import attributes: + +```js title="index.js" +import json from './example.json' with { type: 'json' }; +``` + +In bundleless mode, when importing JSON files through import attributes, you need to ensure that references to the JSON files are preserved in the output, refer to [document](#bundleless) for configuration. + ## YAML file [YAML](https://yaml.org/) is a data serialization language commonly used for writing configuration files. diff --git a/website/docs/zh/guide/advanced/json-files.mdx b/website/docs/zh/guide/advanced/json-files.mdx index fe9c07dbc..f44b3ee8c 100644 --- a/website/docs/zh/guide/advanced/json-files.mdx +++ b/website/docs/zh/guide/advanced/json-files.mdx @@ -102,6 +102,16 @@ export { __webpack_exports__items as items, __webpack_exports__name as name }; +### 使用 import attributes + +在 bundle 模式下,Rslib 支持 [import attributes](https://github.com/tc39/proposal-import-attributes),你可以通过 import attributes 来引入 JSON 文件: + +```js title="index.js" +import json from './example.json' with { type: 'json' }; +``` + +在 bundleless 模式下,通过 import attributes 引入 JSON 文件时,需要确保产物中保留对 JSON 文件的引用,参考 [文档](#bundleless) 进行配置。 + ## YAML 文件 [YAML](https://yaml.org/) 是一种数据序列化语言,通常用于编写配置文件。