Rslib supports importing JSON files in code, and also supports importing YAML and TOML files and converting them to JSON format.
You can directly import JSON files in JavaScript files.
In bundle mode, JSON files support both default and named import.
In bundleless mode, JSON files only support named import.
Rslib also supports importing JSON files through named import.
Here is an example, assuming the source code is as follows:
Based on the configuration in the output structure specified in the configuration file, the following outputs will be emitted:
YAML is a data serialization language commonly used for writing configuration files.
By adding the @rsbuild/plugin-yaml plugin, you can import .yaml
or .yml
files in JavaScript and they will be automatically converted to JavaScript objects.
You can register the plugin in the rslib.config.ts
file:
TOML is a semantically explicit, easy-to-read configuration file format.
By adding the @rsbuild/plugin-toml plugin, you can import .toml
files in JavaScript and it will be automatically converted to JavaScript objects.
You can register the plugin in the rslib.config.ts
file:
When you import YAML or Toml files in TypeScript code, please create a src/env.d.ts
file in your project and add the corresponding type declarations.
@rslib/core
package is installed, you can reference the preset types provided by @rslib/core
: