2021-08-07 04:51:22 -04:00
|
|
|
#[cfg(feature = "js-esbuild")]
|
|
|
|
use {
|
|
|
|
crate::minify::esbuild::minify_using_esbuild,
|
2021-08-08 02:16:12 -04:00
|
|
|
esbuild_rs::{Charset, LegalComments, SourceMap, TransformOptions, TransformOptionsBuilder},
|
2021-08-07 04:51:22 -04:00
|
|
|
lazy_static::lazy_static,
|
|
|
|
std::sync::Arc,
|
|
|
|
};
|
2021-08-06 02:17:45 -04:00
|
|
|
|
2021-08-07 04:51:22 -04:00
|
|
|
use crate::Cfg;
|
|
|
|
|
|
|
|
#[cfg(feature = "js-esbuild")]
|
|
|
|
lazy_static! {
|
|
|
|
static ref TRANSFORM_OPTIONS: Arc<TransformOptions> = {
|
|
|
|
let mut builder = TransformOptionsBuilder::new();
|
2021-08-08 02:16:12 -04:00
|
|
|
builder.charset = Charset::UTF8;
|
|
|
|
builder.legal_comments = LegalComments::None;
|
2021-08-07 04:51:22 -04:00
|
|
|
builder.minify_identifiers = true;
|
|
|
|
builder.minify_syntax = true;
|
|
|
|
builder.minify_whitespace = true;
|
2021-08-08 02:16:12 -04:00
|
|
|
builder.source_map = SourceMap::None;
|
2021-08-07 04:51:22 -04:00
|
|
|
builder.build()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "js-esbuild"))]
|
2021-08-06 09:18:45 -04:00
|
|
|
pub fn minify_js(_cfg: &Cfg, out: &mut Vec<u8>, code: &[u8]) {
|
2021-08-07 04:51:22 -04:00
|
|
|
out.extend_from_slice(&code);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "js-esbuild")]
|
|
|
|
pub fn minify_js(cfg: &Cfg, out: &mut Vec<u8>, code: &[u8]) {
|
|
|
|
if !cfg.minify_js {
|
|
|
|
out.extend_from_slice(&code);
|
|
|
|
} else {
|
2021-08-08 03:18:50 -04:00
|
|
|
minify_using_esbuild(
|
|
|
|
out,
|
|
|
|
code,
|
|
|
|
&TRANSFORM_OPTIONS.clone(),
|
|
|
|
);
|
2021-08-07 04:51:22 -04:00
|
|
|
}
|
2021-08-06 02:17:45 -04:00
|
|
|
}
|