Installing a Vite or Rollup plugin
Astro builds on top of Vite, and supports both Vite and Rollup plugins. This recipe uses a Rollup plugin to add the ability to import a YAML (.yml) file in Astro.
Recipe
Section titled “Recipe”-
Install
@rollup/plugin-yaml:Terminal window npm install @rollup/plugin-yaml --save-devTerminal window pnpm add @rollup/plugin-yaml --save-devTerminal window yarn add @rollup/plugin-yaml --dev -
Import the plugin in your
astro.config.mjsand add it to the Vite plugins array:astro.config.mjs import { defineConfig } from 'astro/config';import yaml from '@rollup/plugin-yaml';export default defineConfig({vite: {plugins: [yaml()]}}); -
Finally, you can import YAML data using an
importstatement:import yml from './data.yml';