跳转到内容

安装 Vite 或 Rollup 插件

Astro 构建于 Vite 之上,同时支持 Vite 和 Rollup 插件。本方案使用一个 Rollup 插件来添加在 Astro 中导入 YAML (.yml) 文件的功能。

  1. 安装 @rollup/plugin-yaml

    终端窗口
    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';
贡献 社区 赞助