Vite plugin to import YAML files as JavaScript default exports. Current stable version is 1.1.5, released with basic YAML loading support. The plugin registers a Vite plugin that transforms .yaml and .yml files into JS objects via default export. It is a lightweight alternative to vite-plugin-yaml (which may have different export behavior) and does not require additional loaders. Release cadence appears low; the package has had only a few bug fix releases since v1.0.0. The plugin is minimal, with no configuration options beyond the plugin call.
npm install vite-plugin-yaml2Verified import paths — ran on the pinned version, not inferred.
Shows how to register the plugin in vite.config.ts and import a YAML file.
Add declare module '*.yaml' { const value: any; export default value; } in a .d.ts file.If issues arise with newer Vite versions, consider using vite-plugin-yaml (alternative) or file an issue.
Validate YAML syntax before importing.
Ensure vite-plugin-yaml2 is installed: npm i vite-plugin-yaml2. For YAML files, add type declarations as shown in the quickstart warnings.
Use import pluginYaml from 'vite-plugin-yaml2' instead of import { pluginYaml } from ...Install yaml: npm i yaml (or it should be automatically installed as a dependency of vite-plugin-yaml2, but manual install may fix).
Add declare module '*.yaml' { const value: any; export default value; } to src/vite-env.d.ts.