Skip to content

silverwind/vite-yaml-plugin

Repository files navigation

vite-yaml-plugin

Vite plugin to import YAML files, with minimal dependencies

Usage

vite.config.js

import {defineConfig} from "vite";
import {yamlPlugin} from "vite-yaml-plugin";

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

file.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:

{
  "compilerOptions": {
    "types": [
      "vite-yaml-plugin/types"
    ]
  }
}

Alternatively, you can also add ambient type declarations:

declare module "*.yaml" {
  const value: Record<string, any>;
  export default value;
}
declare module "*.yml" {
  const value: Record<string, any>;
  export default value;
}

Related

About

Vite plugin to import YAML files

Resources

Stars

Watchers

Forks

Packages

No packages published