Expand description
Rolldown plugin for Astro components
This plugin extracts and processes frontmatter and <script> blocks from Astro
components, making them available to the bundler as JavaScript/TypeScript modules.
§Architecture
.astro file → load() hook → AstroExtractor → Extract frontmatter + scripts → JS/TS → Rolldown§Why the load hook?
We use the load hook (not transform) because:
- Astro components aren’t valid JavaScript/TypeScript that Rolldown can parse
- We must intercept files before Rolldown’s parser runs
- The
loadhook is designed for custom file formats - We return extracted JavaScript with the appropriate
ModuleType
§Handling Frontmatter and Scripts
Astro components can contain:
- One frontmatter block at the start (delimited by
---, TypeScript by default) - Multiple
<script>tags in the template (JavaScript by default)
Frontmatter runs on the server during build/SSR, while script tags run in the browser. When both exist, we combine them with frontmatter first, as it executes during the component’s module loading phase.
§Example Usage
use fob_plugin_astro::FobAstroPlugin;
use std::sync::Arc;
let plugin = Arc::new(FobAstroPlugin::new());
// Add to your Rolldown bundler configurationStructs§
- FobAstro
Plugin - Rolldown plugin that extracts JavaScript/TypeScript from Astro components