Crates.io | brk_bundler |
lib.rs | brk_bundler |
version | 0.0.95 |
created_at | 2025-06-14 23:51:05.150999+00 |
updated_at | 2025-08-28 10:44:15.387311+00 |
description | A thin wrapper around rolldown |
homepage | https://bitcoinresearchkit.org |
repository | https://github.com/bitcoinresearchkit/brk |
max_upload_size | |
id | 1712755 |
size | 91,414 |
Asset bundling for BRK web interfaces using Rolldown
brk_bundler
provides JavaScript/TypeScript bundling capabilities for BRK's web interfaces. It's a thin wrapper around Rolldown (Rust-based Rollup alternative) with BRK-specific configuration for building optimized web assets with file watching and automatic rebuilding.
use brk_bundler::bundle;
use std::path::Path;
// Bundle without watching (production)
let websites_path = Path::new("./websites");
let source_folder = "default";
let dist_path = bundle(websites_path, source_folder, false).await?;
println!("Bundled to: {:?}", dist_path);
// Bundle with file watching (development)
let dist_path = bundle(websites_path, "default", true).await?;
// Bundler now watches for changes and rebuilds automatically
// This will run in the background until the process exits
// Typically called from brk_cli when serving websites
async fn setup_website(config: &Config) -> Result<PathBuf> {
let websites_path = config.websites_path();
let source_folder = match config.website_mode {
WebsiteMode::Default => "default",
WebsiteMode::Custom => "custom",
WebsiteMode::None => return Ok(PathBuf::new()),
};
// Bundle the website assets
let dist_path = bundle(websites_path, source_folder, config.dev_mode).await?;
Ok(dist_path)
}
The bundler expects this directory structure:
websites/
├── default/ # Default website source
│ ├── index.html # Main HTML file
│ ├── service-worker.js # Service worker (version injected)
│ ├── scripts/ # JavaScript/TypeScript source
│ │ ├── entry.js # Main entry point
│ │ ├── main.js # Application logic
│ │ └── ... # Other JS modules
│ └── assets/ # Static assets
└── dist/ # Generated output directory
├── index.html # Processed HTML with updated script references
├── service-worker.js # Service worker with version injected
├── scripts/ # Bundled and minified JavaScript
│ └── main-[hash].js # Hashed output file
└── assets/ # Copied static assets
dist/
directorydist/
scripts/entry.js
as entry pointThe bundler uses Rolldown with these optimized settings:
BundlerOptions {
input: Some(vec![source_entry.into()]), // scripts/entry.js
dir: Some("./dist/scripts".to_string()), // Output directory
cwd: Some(websites_path), // Working directory
minify: Some(RawMinifyOptions::Bool(true)), // Enable minification
sourcemap: Some(SourceMapType::File), // Generate source maps
..Default::default()
}
In watch mode, the bundler monitors:
Create
- New files addedModify
- Existing files changedDelete
and other eventsService workers get automatic version injection:
// In source service-worker.js
const VERSION = '__VERSION__';
// After bundling
const VERSION = 'v0.0.88';
This enables proper cache invalidation across releases.
brk_rolldown
- Rust-based Rollup bundlernotify
- File system watchingtokio
- Async runtime for file operationssugar_path
- Path manipulation utilitieslog
- Error loggingThe bundler integrates with:
This README was generated by Claude Code