安装一个 Vite 或 Rollup 插件
Astro 基于 Vite 构建,并支持 Vite 和 Rollup 插件。该操作指南使用 Rollup 插件来添加在 Astro 中导入 YAML(.yml)文件的能力。
-
安装
@rollup/plugin-yaml:终端窗口 npm install @rollup/plugin-yaml --save-dev终端窗口 pnpm add @rollup/plugin-yaml --save-dev终端窗口 yarn add @rollup/plugin-yaml --dev -
在
astro.config.mjs中导入插件并将其添加到 Vite 插件数组中:astro.config.mjs import { defineConfig } from 'astro/config';import yaml from '@rollup/plugin-yaml';export default defineConfig({vite: {plugins: [yaml()]}}); -
最后,你可以使用
import语句导入 YAML 数据:import yml from './data.yml';