close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo

Getting Started

Introduction
Quick start
Features
Glossary

Framework

React
Vue
Preact
Svelte
Solid

Basic

CLI
Dev server
Output files
Static assets
HTML
JSON
Wasm
TypeScript
Web Workers
Deploy static site
Upgrade Rsbuild

Configuration

Configure Rspack
Configure Rsbuild
Configure SWC

Styling

CSS
CSS Modules
CSS-in-JS
Tailwind CSS v4
Tailwind CSS v3
UnoCSS

Advanced

Path aliases
Environment variables
Hot module replacement
Browserslist
Browser compatibility
Module Federation
Multi-environment builds
Server-side rendering (SSR)
Testing

Optimization

Code splitting
Bundle size optimization
Improve build performance
Inline static assets

Migration

Migrating from Rsbuild 0.x
webpack
Create React App
Vue CLI
Vite
Vite plugin
Modern.js Builder

Debug

Debug mode
Build profiling
Use Rsdoctor

FAQ

General FAQ
Features FAQ
Exceptions FAQ
HMR FAQ
📝 Edit this page on GitHub
Previous PageHTML
Next PageWasm

#JSON

Rsbuild supports importing JSON files in code, and also supports importing YAML and TOML files, converting them to JSON format.

#JSON file

You can import JSON files directly in JavaScript files.

#Example

example.json
{
  "name": "foo",
  "items": [1, 2]
}
index.js
import example from './example.json';

console.log(example.name); // 'foo';
console.log(example.items); // [1, 2];

#Named import

Rsbuild also supports importing JSON files using named imports:

import { name } from './example.json';

console.log(name); // 'foo';

#YAML file

YAML is a data serialization language commonly used for writing configuration files.

Rsbuild provides the @rsbuild/plugin-yaml. After registering the plugin, you can import .yaml or .yml files in JavaScript and they will be automatically converted to JavaScript objects.

rsbuild.config.ts
import { pluginYaml } from '@rsbuild/plugin-yaml';

export default {
  plugins: [pluginYaml()],
};

#Example

example.yaml
---
hello: world
foo:
  bar: baz
import example from './example.yaml';

console.log(example.hello); // 'world';
console.log(example.foo); // { bar: 'baz' };

#TOML file

TOML is a semantically explicit, easy-to-read configuration file format.

Rsbuild provides the @rsbuild/plugin-toml. After registering the plugin, you can import .toml files in JavaScript and it will be automatically converted to JavaScript objects.

rsbuild.config.ts
import { pluginToml } from '@rsbuild/plugin-toml';

export default {
  plugins: [pluginToml()],
};

#Example

example.toml
hello = "world"

[foo]
bar = "baz"
import example from './example.toml';

console.log(example.hello); // 'world';
console.log(example.foo); // { bar: 'baz' };

#Type declaration

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.

  • Method 1: If the @rsbuild/core package is installed, you can reference the preset types provided by @rsbuild/core:
src/env.d.ts
/// <reference types="@rsbuild/core/types" />
  • Method 2: Manually add the required type declarations:
src/env.d.ts
declare module '*.yaml' {
  const content: Record<string, any>;
  export default content;
}
declare module '*.yml' {
  const content: Record<string, any>;
  export default content;
}
declare module '*.toml' {
  const content: Record<string, any>;
  export default content;
}