fob-plugin-astro 0.2.1

Rolldown bundler plugin for Astro - extract and process frontmatter and script blocks from Astro components
Documentation

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 load hook 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;

# async fn example() -> Result<(), Box<dyn std::error::Error>> {
let plugin = Arc::new(FobAstroPlugin::new());
// Add to your Rolldown bundler configuration
# Ok(())
# }