jsmeld
A library-only wrapper around SWC for compiling and bundling JavaScript in Rust and Python.
Rust usage
Both compile and bundle take a file path and a JSMeldOptions struct:
use ;
// Compile a single file
let output = compile?;
// Bundle an entry point
let output = bundle?;
JSMeldOptions
A single unified options struct used by both compilation and bundling.
| Field | Type | Default | Used by |
|---|---|---|---|
target |
String |
"es6" |
both |
minify |
bool |
false |
both |
source_map |
bool |
true |
both |
typescript |
bool |
true |
compile |
module |
String |
"esm" |
compile |
strict |
bool |
true |
compile |
code_split |
bool |
false |
bundle |
externals |
Vec<String> |
[] |
bundle |
style_hooks |
HashMap<String, Vec<StyleTransformHook>> |
{} |
bundle |
Style hooks
JSMeldOptions supports style transformation hooks keyed by file extension.
Hooks are executed in order when a matching style file is loaded during bundling.
Each key is a file extension (e.g. "css", "less") and each value is an ordered list of hook closures.
Hook type:
type StyleTransformHook = ;
Registering hooks in JSMeldOptions
use Arc;
use HashMap;
use ;
let mut options = default;
options.style_hooks.insert;
options.style_hooks.entry.or_default.push;
let bundler = new;
let output = bundler.bundle?;
Registering hooks via Bundler
If you initialize a Bundler with options, you can append hooks per extension:
use Arc;
use ;
let mut bundler = new;
bundler.add_style_hook;
Notes:
- Extensions are normalized to lowercase.
- Leading dots are allowed (e.g.
".css"). - Hooks run only for matching style-file extensions.
Python usage
The Python package exposes two top-level functions. Both accept an optional
options dictionary with the same keys as JSMeldOptions above.
# Compile a single file (all options are optional)
: =
# Bundle an entry point
: =
Style hooks from Python
style_hooks can be passed as a dictionary mapping file extensions to lists
of callables (path: str, source: str) -> str:
return f
=