Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rspack-contrib/rsbuild-plugin-yaml

An Rsbuild plugin to import YAML files and convert them into JavaScript objects.
https://github.com/rspack-contrib/rsbuild-plugin-yaml

rsbuild rsbuild-plugin rspack

Last synced: 16 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# @rsbuild/plugin-yaml

Import YAML files and convert them into JavaScript objects.

> [YAML](https://yaml.org/) is a data serialization language commonly used for writing configuration files.



npm version

license

## Usage

Install:

```bash
npm add @rsbuild/plugin-yaml -D
```

Add plugin to your `rsbuild.config.ts`:

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

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

## Example

Suppose the project has the following code in `example.yaml`:

```yaml title="example.yaml"
hello = "world"

[foo]
bar = "baz"
```

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

```js
import example from "./example.yaml";

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

## Type Declaration

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

```ts
declare module "*.yml" {
const content: Record;
export default content;
}
declare module "*.yaml" {
const content: Record;
export default content;
}
```

## License

[MIT](./LICENSE).