1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use ;
use ;
use crate::;
/// Represents a compiled JavaScript module ready for inclusion in the output site.
///
/// Each [`Script`] corresponds to a `.js`, `.ts`, or `.tsx` source file that has been
/// bundled and minified using `esbuild`. The compiled output is stored under a
/// hashed filename, and the `path` can be used in templates.
/// Constructs a loader that compiles JavaScript/TypeScript files using `esbuild`.
///
/// Matches files based on a glob pattern and compiles each into a minified
/// ES module using `esbuild` with bundling enabled. Each output is content-hashed
/// and written to disk. The resulting `Script` provides the path to that output.
///
/// ### Parameters
/// - `path_base`: Base directory for relative resolution of the glob.
/// - `path_glob`: Glob pattern used to select `.js`, `.ts`, etc. source files.
///
/// ### Returns
/// A `Loader` that emits `Script` objects keyed by hashed output content.
///
/// ### Requirements
/// - `esbuild` must be installed and available on `$PATH`.
///
/// ### Example
/// ```rust
/// use hauchiwa::{Context, TaskResult, Page, loader::{Script, glob_scripts}};
///
/// // loader
/// let loader = glob_scripts("src/scripts", "**/*.ts");
///
/// // task
/// fn task(ctx: Context) -> TaskResult<Vec<Page>> {
/// let Script { path } = ctx.get::<Script>("main.ts")?;
///
/// Ok(vec![
/// Page::text("index.html".into(), format!("<script type='module' src='{path}'></script>"))
/// ])
/// }
/// ```