Skip to main content

minify_inline_js_snippets

Function minify_inline_js_snippets 

Source
pub async fn minify_inline_js_snippets(out_dir: &Path) -> Result<(), EuvError>
Expand description

Minifies every wasm-bindgen inline_js snippet file emitted under <out_dir>/<pkg>/snippets/**/inline*.js.

#[wasm_bindgen(inline_js = ...)] blocks are extracted verbatim from the Rust source by wasm-bindgen — preserving indentation, comments, and original identifier names — and written into per-crate snippet directories inside pkg/snippets/<crate-hash>/. On a typical euv build this costs roughly 2 KB of uncompressed JS to ship to every browser; minifying in-place brings the payload down to ~700 B with no semantic change. The export names are preserved so the wasm glue loader (euv_example.js’s __wbg_* init) can still resolve them by name.

Failures are logged and skipped so a single bad snippet does not abort the overall build — a syntax error in an inline snippet will already have been caught by wasm-pack itself. We only touch files whose stem starts with SNIPPET_FILE_PREFIX and whose extension matches JS_EXTENSION, leaving any other file under snippets/ alone.

§Arguments

  • &Path - The build output directory (typically <crate>/www/pkg).

§Returns

  • Result<(), EuvError> - Ok(()) on success, or a wrapped I/O error.