@rsbuild/plugin-toml
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@rsbuild/plugin-toml

An Rsbuild plugin to import TOML files and convert them to JavaScript objects.

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

npm version license

Usage

Install:

npm add @rsbuild/plugin-toml -D

Add plugin to your rsbuild.config.ts:

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

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

Example

Suppose the project has the following code in example.toml:

hello = "world"

[foo]
bar = "baz"

After using the TOML plugin, you can reference it as follows:

import example from "./example.toml";

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

Options

esModule

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: boolean
  • Default: true
  • Example:
pluginToml({
  exModule: false,
});

Type Declaration

When you import TOML files in TypeScript code, please create a src/env.d.ts file in your project and add the type declarations.

declare module "*.toml" {
  const content: Record<string, any>;
  export default content;
}

License

MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i @rsbuild/plugin-toml

Weekly Downloads

4,571

Version

1.0.1

License

MIT

Unpacked Size

7.45 kB

Total Files

7

Last publish

Collaborators

  • chenjiahan
  • hardfist