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.

  1. Install @rollup/plugin-yaml:

    ターミナルウィンドウ
    npm install @rollup/plugin-yaml --save-dev

    Copied!

  2. Import the plugin in your astro.config.mjs and 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()]
      }
    });

    Copied!

  3. Finally, you can import YAML data using an import statement:

    import yml from './data.yml';

    Copied!


その他のレシピ