跳转到内容

安装一个 Vite 或 Rollup 插件

Astro 基于 Vite 构建,并支持 Vite 和 Rollup 插件。该操作指南使用 Rollup 插件来添加在 Astro 中导入 YAML(.yml)文件的能力。

  1. 安装 @rollup/plugin-yaml

    Terminal window
    npm install @rollup/plugin-yaml --save-dev
  2. astro.config.mjs 中导入插件并将其添加到 Vite 插件数组中:

    astro.config.mjs
    import { defineConfig } from 'astro/config';
    import yaml from '@rollup/plugin-yaml';
    export default defineConfig({
    vite: {
    plugins: [yaml()]
    }
    });
  3. 最后,你可以使用 import 语句导入 YAML 数据:

    import yml from './data.yml';