Function minify

Source
pub fn minify<'a>(
    session: &'a Session,
    top_level_mode: TopLevelMode,
    source: &'a [u8],
    output: &mut Vec<u8>,
) -> Result<(), SyntaxError<'a>>
Expand description

Minifies UTF-8 JavaScript code, represented as an array of bytes.

§Arguments

  • session - Session to use as backing arena memory. Can be reused across calls and cleared at any time allowed by the Rust lifetime checker.
  • top_level_mode - How to parse the provided code.
  • source - A vector of bytes representing the source code to minify.
  • output - Destination to write minified output JavaScript code.

§Examples

use minify_js::{Session, TopLevelMode, minify};

let mut code: &[u8] = b"const main = () => { let my_first_variable = 1; };";
let session = Session::new();
let mut out = Vec::new();
minify(&session, TopLevelMode::Global, code, &mut out).unwrap();
assert_eq!(out.as_slice(), b"const main=()=>{let a=1}");