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