File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 22
33An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
44
5+ > [ TOML] ( https://toml.io/ ) is a semantically explicit, easy-to-read configuration file format.
6+
57<p >
68 <a href =" https://npmjs.com/package/@rsbuild/plugin-toml " >
79 <img src =" https://img.shields.io/npm/v/@rsbuild/plugin-toml?style=flat-square&colorA=564341&colorB=EDED91 " alt =" npm version " />
@@ -28,6 +30,37 @@ export default {
2830};
2931```
3032
33+ ## Example
34+
35+ Suppose the project has the following code in ` example.toml ` :
36+
37+ ``` toml title="example.toml"
38+ hello = " world"
39+
40+ [foo ]
41+ bar = " baz"
42+ ```
43+
44+ After using the TOML plugin, you can reference it as follows:
45+
46+ ``` js
47+ import example from " ./example.toml" ;
48+
49+ console .log (example .hello ); // 'world';
50+ console .log (example .foo ); // { bar: 'baz' };
51+ ```
52+
53+ ## Type Declaration
54+
55+ When you import TOML files in TypeScript code, please create a ` src/env.d.ts ` file in your project and add the type declarations.
56+
57+ ``` ts title="src/env.d.ts"
58+ declare module " *.toml" {
59+ const content: Record <string , any >;
60+ export default content ;
61+ }
62+ ```
63+
3164## License
3265
3366[ MIT] ( ./LICENSE ) .
You can’t perform that action at this time.
0 commit comments