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.
Install @rollup/plugin-yaml:
npm install @rollup/plugin-yaml --save-dev
pnpm add @rollup/plugin-yaml --save-dev
yarn add @rollup/plugin-yaml --dev
Import the plugin in your astro.config.mjs and add it to the Vite plugins array:
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 import statement:
import yml from './data.yml';
© 2021 Fred K. Schott
Licensed under the MIT License.
https://docs.astro.build/en/recipes/add-yaml-support/