Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/rspack-contrib/rsbuild-plugin-yaml
- Owner: rspack-contrib
- License: mit
- Created: 2024-06-30T11:17:58.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-01T01:47:03.000Z (26 days ago)
- Last Synced: 2024-12-01T02:31:07.374Z (26 days ago)
- Topics: rsbuild, rsbuild-plugin, rspack
- Language: TypeScript
- Homepage:
- Size: 71.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rspack - @rsbuild/plugin-yaml
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.
## 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).