| Crates.io | brk_bundler |
| lib.rs | brk_bundler |
| version | 0.0.109 |
| created_at | 2025-06-14 23:51:05.150999+00 |
| updated_at | 2025-09-20 17:20:42.1793+00 |
| description | A thin wrapper around rolldown |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1712755 |
| size | 99,011 |
Asset bundling and development server for BRK web interfaces with hot reloading and file watching.
This crate provides a thin wrapper around the Rolldown JavaScript bundler specifically designed for BRK web interface development. It handles asset bundling, file copying, template processing, and development-mode file watching with automatic rebuilds and hot reloading for efficient web development workflows.
Key Features:
Target Use Cases:
cargo add brk_bundler
use brk_bundler::bundle;
use std::path::Path;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let websites_path = Path::new("./web");
let source_folder = "src";
let watch = true; // Enable hot reloading
// Bundle assets and start development server
let dist_path = bundle(websites_path, source_folder, watch).await?;
println!("Assets bundled to: {}", dist_path.display());
// Keep running for file watching (in watch mode)
if watch {
tokio::signal::ctrl_c().await?;
}
Ok(())
}
bundle(websites_path: &Path, source_folder: &str, watch: bool) -> io::Result<PathBuf>
Main bundling function that processes web assets and optionally starts file watching.
dist/ directory and copies source filesscripts/entry.js with Rolldown bundlerindex.html with hashed asset referencesRolldown Bundler Options:
./src/scripts/entry.js (main JavaScript entry point)./dist/scripts/ directoryuse brk_bundler::bundle;
use std::path::Path;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let web_root = Path::new("./websites");
// Start development server with file watching
let _dist_path = bundle(web_root, "explorer", true).await?;
println!("Development server started!");
println!("Hot reloading enabled - edit files to see changes");
// Keep server running
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
}
use brk_bundler::bundle;
use std::path::Path;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let web_root = Path::new("./websites");
// Build for production (no watching)
let dist_path = bundle(web_root, "dashboard", false).await?;
println!("Production build completed: {}", dist_path.display());
// Assets are minified and ready for deployment
Ok(())
}
use brk_bundler::bundle;
use std::path::Path;
// Expected directory structure:
// websites/
// ├── my_app/
// │ ├── index.html // Main HTML template
// │ ├── service-worker.js // Service worker template
// │ ├── scripts/
// │ │ └── entry.js // JavaScript entry point
// │ ├── styles/
// │ │ └── main.css // CSS files
// │ └── assets/
// │ └── images/ // Static assets
// └── dist/ // Generated output
#[tokio::main]
async fn main() -> std::io::Result<()> {
let websites_path = Path::new("./websites");
let source_folder = "my_app";
let dist_path = bundle(websites_path, source_folder, false).await?;
// Result: dist/ contains bundled and processed files
// - dist/index.html (with updated script references)
// - dist/service-worker.js (with version injection)
// - dist/scripts/main.[hash].js (minified and hashed)
// - dist/styles/ (copied CSS files)
// - dist/assets/ (copied static assets)
Ok(())
}
Development Mode Watchers:
Event Handling:
index.html Processing:
/scripts/main.js with /scripts/main.[hash].jsservice-worker.js Processing:
__VERSION__ placeholder with current crate versionBuilt on Tokio async runtime:
The bundler uses optimized Rolldown settings:
BundlerOptions {
input: Some(vec!["./src/scripts/entry.js".into()]),
dir: Some("./dist/scripts".to_string()),
minify: Some(RawMinifyOptions::Bool(true)),
sourcemap: Some(SourceMapType::File),
// ... other default options
}
Required Files:
src/scripts/entry.js - JavaScript entry pointsrc/index.html - HTML templatesrc/service-worker.js - Service worker templateOptional Directories:
src/styles/ - CSS stylesheetssrc/assets/ - Static assets (images, fonts, etc.)src/components/ - Additional JavaScript moduleswebsites/app_name/dist/ directory contentsMain Function: bundle() async function coordinating Rolldown bundler with file processing and watching
File Operations: Recursive directory copying with copy_dir_all() and selective file processing
Templating: String replacement for asset hash injection and version management
File Watching: Multi-watcher system using notify crate for real-time development feedback
Async Integration: Tokio-based async architecture with background task spawning
Bundler Integration: Rolldown wrapper with optimized configuration for web development
Architecture: Development-focused asset pipeline with hot reloading and production optimization
This README was generated by Claude Code