Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rspack-contrib/rsbuild-plugin-toml
An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
https://github.com/rspack-contrib/rsbuild-plugin-toml
rsbuild rsbuild-plugin rspack
Last synced: 16 days ago
JSON representation
An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
- Host: GitHub
- URL: https://github.com/rspack-contrib/rsbuild-plugin-toml
- Owner: rspack-contrib
- License: mit
- Created: 2024-06-30T08:32:02.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-11-10T11:06:24.000Z (about 2 months ago)
- Last Synced: 2024-11-10T12:17:28.425Z (about 2 months ago)
- Topics: rsbuild, rsbuild-plugin, rspack
- Language: TypeScript
- Homepage:
- Size: 141 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rspack - @rsbuild/plugin-toml
README
# @rsbuild/plugin-toml
An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
> [TOML](https://toml.io/) is a semantically explicit, easy-to-read configuration file format.
## Usage
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()],
};
```## Example
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' };
```## 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:```js
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.
```ts title="src/env.d.ts"
declare module "*.toml" {
const content: Record;
export default content;
}
```## License
[MIT](./LICENSE).