fob-bundler 0.5.0

Fob bundler - Rolldown-based bundling on top of fob foundation
Documentation

fob-bundler

Fob bundler - Rolldown-based bundling on top of fob foundation.

This crate provides full bundling capabilities using Rolldown, building on top of the fob foundation crate for graph analysis and runtime abstraction.

Quick Start

Bundle a library

use fob_bundler as fob;

# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = fob::BuildOptions::new("./src/index.js")
    .platform(fob::Platform::Node)  // Uses Node.js export conditions
    .externalize(["react", "react-dom"])
    .sourcemap(true)
    .build()
    .await?;

let bundle = result.output.as_single().expect("single bundle");
for asset in bundle.assets.iter() {
    std::fs::write(format!("dist/{}", asset.filename()), asset.content_as_bytes())?;
}
# Ok(()) }

Using BuildConfig (Recommended for New Code)

BuildConfig provides a cleaner API with better type safety:

use fob_bundler::BuildConfig;

# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = BuildConfig::new("./src/index.js")
    .bundle(false)
    .output_dir("dist")
    .build()
    .await?;

result.write_to("dist", true)?;
# Ok(()) }

Analyze without bundling

use fob_bundler as fob;

# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error>> {
let analysis = fob_graph::analyze(["./src/index.js"]).await?;
for unused in analysis.graph.unused_exports()? {
    println!("unused: {} from {}", unused.export.name, unused.module_id);
}
# Ok(()) }