From db3563f20f74eab34e2c268e2a159325df315085 Mon Sep 17 00:00:00 2001 From: Xe Date: Fri, 9 Dec 2022 00:12:21 -0500 Subject: [PATCH] nix/make-bundled: add minification option Signed-off-by: Xe --- flake.nix | 1 + nix/make-bundled.nix | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index bc2bcaa..478ae18 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,7 @@ output = "bundled.js"; entrypoint = "./mod.ts"; importMap = "./import_map.json"; + minify = true; }; packages.bundled-wrapper = deno2nix.mkBundledWrapper { pname = "example-bundled-wrapper"; diff --git a/nix/make-bundled.nix b/nix/make-bundled.nix index 001ece5..79d130d 100644 --- a/nix/make-bundled.nix +++ b/nix/make-bundled.nix @@ -11,6 +11,7 @@ lockfile, output ? "bundled.js", outPath ? "dist", + minify ? false, entrypoint, importMap ? null, additionalDenoFlags ? "", @@ -19,7 +20,7 @@ in stdenv.mkDerivation { inherit pname version entrypoint src; - buildInputs = with pkgs; [deno jq]; + buildInputs = with pkgs; [ deno jq nodePackages.uglify-js ]; buildPhase = '' export DENO_DIR="/tmp/deno2nix" @@ -28,7 +29,7 @@ in deno bundle \ --lock="${lockfile}" \ - ${ + ${ if importMap != null then "--import-map=\"$src/${importMap}\"" else "" @@ -36,6 +37,15 @@ in ${additionalDenoFlags} \ "$src/${entrypoint}" \ "${output}" + + ${ + if minify + then '' + mv ${output} ${output}-non-min + uglifyjs ${output}-non-min -c -m > ${output} + '' + else "" + } ''; installPhase = '' mkdir -p $out/${outPath}