An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
npm install @rsbuild/plugin-tomlAn Rsbuild plugin to import TOML files and convert them to JavaScript objects.
> TOML is a semantically explicit, easy-to-read configuration file format.
Install:
``bash`
npm add @rsbuild/plugin-toml -D
Add plugin to your rsbuild.config.ts:
`ts
// rsbuild.config.ts
import { pluginToml } from "@rsbuild/plugin-toml";
export default {
plugins: [pluginToml()],
};
`
Suppose the project has the following code in example.toml:
`toml title="example.toml"
hello = "world"
[foo]
bar = "baz"
`
After using the TOML plugin, you can reference it as follows:
`js
import example from "./example.toml";
console.log(example.hello); // 'world';
console.log(example.foo); // { bar: 'baz' };
`
By default, @rsbuild/plugin-toml generates JS modules that use the ES modules syntax. If you want to generate a CommonJS module, you can set the esModule option to false.
- Type: booleantrue
- Default:
- Example:
`js`
pluginToml({
esModule: false,
});
When you import TOML files in TypeScript code, please create a src/env.d.ts file in your project and add the type declarations.
`ts title="src/env.d.ts"``
declare module "*.toml" {
const content: Record
export default content;
}
MIT.