nix/make-bundled: add minification option

Signed-off-by: Xe <me@christine.website>
This commit is contained in:
Xe 2022-12-09 00:12:21 -05:00
parent 89969955be
commit db3563f20f
2 changed files with 13 additions and 2 deletions

View file

@ -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";

View file

@ -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}