Skip to main content

Library/Fn/Bundle/
mod.rs

1//! Bundling and esbuild integration
2//!
3//! This module provides:
4//! - Simple bundling capabilities for the Rest compiler
5//! - Optional esbuild integration for complex builds
6//! - Multi-file compilation support
7
8pub mod config;
9pub mod builder;
10pub mod esbuild;
11
12pub use config::BundleConfig;
13pub use builder::BundleBuilder;
14pub use esbuild::EsbuildWrapper;
15
16/// Result of a bundling operation
17#[derive(Debug, Clone)]
18pub struct BundleResult {
19	/// Path to the bundled output file
20	pub output_path:String,
21	/// Source map path (if generated)
22	pub source_map_path:Option<String>,
23	/// List of bundled files
24	pub bundled_files:Vec<String>,
25	/// Bundle hash for cache invalidation
26	pub hash:String,
27}
28
29/// Represents a bundle entry (file to be bundled)
30#[derive(Debug, Clone)]
31pub struct BundleEntry {
32	/// Path to the source file
33	pub source:String,
34	/// Module name (for ESM exports)
35	pub module_name:Option<String>,
36	/// Whether this is an entry point
37	pub is_entry:bool,
38}
39
40impl BundleEntry {
41	pub fn new(source:impl Into<String>) -> Self { Self { source:source.into(), module_name:None, is_entry:false } }
42
43	pub fn entry(source:impl Into<String>) -> Self { Self { source:source.into(), module_name:None, is_entry:true } }
44
45	pub fn with_module_name(mut self, name:impl Into<String>) -> Self {
46		self.module_name = Some(name.into());
47		self
48	}
49}
50
51/// Bundling mode
52#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
53pub enum BundleMode {
54	/// Single file compilation (current behavior)
55	#[default]
56	SingleFile,
57	/// Bundle multiple files into one
58	Bundle,
59	/// Watch mode - rebuild on changes
60	Watch,
61	/// Build with esbuild (for complex cases)
62	Esbuild,
63}
64
65impl BundleMode {
66	pub fn requires_bundle(&self) -> bool {
67		matches!(self, BundleMode::Bundle | BundleMode::Esbuild | BundleMode::Watch)
68	}
69}