jsmeld
A 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 |
|---|---|---|
target |
String |
"es6" |
minify |
bool |
false |
source_map |
bool |
true |
typescript |
bool |
true |
module |
String |
"esm" |
strict |
bool |
true |
code_split |
bool |
false |
externals |
Vec<String> |
[] |
style_output |
Option<String> |
None |
style_hooks |
HashMap<String, Vec<StyleTransformHook>> |
{} |
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.
CLI usage
The CLI accepts an input file and output path:
If installed as a binary, replace cargo run -- with jsmeld.
Common commands
Compile a single file:
Bundle an entry point:
Bundle with minification and a target:
Extract styles to dist/bundle.css (default sidecar path):
Extract styles to a custom path:
Notes:
--style-outputimplies style extraction automatically.- If neither
--bundlenor--compileis provided, bundling is used.
Help output
<INPUT> Input )
<OUTPUT> Output
NPM usage
Install the cross-platform CLI package:
Run it via npx:
Or use it from npm scripts:
The top-level jsmeld package uses optionalDependencies to install the
matching prebuilt binary package for your platform.
Published binary package names:
jsmeld-linux-x64-gnujsmeld-linux-arm64-gnujsmeld-linux-x64-musljsmeld-linux-arm64-musljsmeld-darwin-x64jsmeld-darwin-arm64jsmeld-win32-x64-msvcjsmeld-win32-arm64-msvc
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
=