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