https://github.com/silverwind/vite-yaml-plugin
Vite plugin to import YAML files
https://github.com/silverwind/vite-yaml-plugin
Last synced: 4 months ago
JSON representation
Vite plugin to import YAML files
- Host: GitHub
- URL: https://github.com/silverwind/vite-yaml-plugin
- Owner: silverwind
- Created: 2025-01-16T13:01:58.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-05T22:50:47.000Z (about 1 year ago)
- Last Synced: 2025-06-08T21:39:14.190Z (about 1 year ago)
- Language: TypeScript
- Size: 1.16 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vite-yaml-plugin
[](https://www.npmjs.org/package/vite-yaml-plugin) [](https://www.npmjs.org/package/vite-yaml-plugin) [](https://packagephobia.com/result?p=vite-yaml-plugin)
Vite plugin to import YAML files, with minimal dependencies
## Usage
#### vite.config.js
```js
import {defineConfig} from "vite";
import {yamlPlugin} from "vite-yaml-plugin";
export default defineConfig({
plugins: [
yamlPlugin(),
],
});
```
#### file.js
```js
import foo from "./foo.yaml";
```
## Options
- `match`: Regex to match the path against. Default: `/\.(yaml|yml)$/i`.
- `opts`: Options passed to js-yaml's `load` function.
## Typescript
Add `vite-yaml-plugin/types` to your `types` in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"vite-yaml-plugin/types"
]
}
}
```
Alternatively, you can also add ambient type declarations:
```ts
declare module "*.yaml" {
const value: Record;
export default value;
}
declare module "*.yml" {
const value: Record;
export default value;
}
```
## Related
- [`vite-string-plugin`](https://github.com/silverwind/vite-string-plugin)