Skip to content

Commit 48ed6bc

Browse files
authored
docs: use import attributes to import JSON files (#1079)
1 parent dfe008e commit 48ed6bc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

website/docs/en/guide/advanced/json-files.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export { __webpack_exports__items as items, __webpack_exports__name as name };
105105

106106
</Tabs>
107107

108+
### Use import attributes
109+
110+
In bundle mode, Rslib supports [import attributes](https://github.com/tc39/proposal-import-attributes), and you can import JSON files through import attributes:
111+
112+
```js title="index.js"
113+
import json from './example.json' with { type: 'json' };
114+
```
115+
116+
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.
117+
108118
## YAML file
109119

110120
[YAML](https://yaml.org/) is a data serialization language commonly used for writing configuration files.

website/docs/zh/guide/advanced/json-files.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ export { __webpack_exports__items as items, __webpack_exports__name as name };
102102

103103
</Tabs>
104104

105+
### 使用 import attributes
106+
107+
在 bundle 模式下,Rslib 支持 [import attributes](https://github.com/tc39/proposal-import-attributes),你可以通过 import attributes 来引入 JSON 文件:
108+
109+
```js title="index.js"
110+
import json from './example.json' with { type: 'json' };
111+
```
112+
113+
在 bundleless 模式下,通过 import attributes 引入 JSON 文件时,需要确保产物中保留对 JSON 文件的引用,参考 [文档](#bundleless) 进行配置。
114+
105115
## YAML 文件
106116

107117
[YAML](https://yaml.org/) 是一种数据序列化语言,通常用于编写配置文件。

0 commit comments

Comments
 (0)