From 2a69db5d88ce4acda8e7892a351c6a7c790d3172 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 25 Mar 2023 07:56:24 -0400 Subject: static/js: Deno bundle is deprecated - replicate Color outside the lines.. Maybe change to full async no/decoupled build and leave deno for creating eventual APIs for hugo to consume? --- Makefile | 2 +- assets/js/index.js | 6 +----- shell.nix | 1 + static/js/bundle.ts | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 static/js/bundle.ts diff --git a/Makefile b/Makefile index cd04c15..b9b8a85 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ watch: while true; do find . | entr -d -s 'make all'; done js: - deno bundle --no-check --config tsconfig.json static/js/index.ts assets/js/index.js + deno run --allow-all static/js/bundle.ts hugo: rm -rf public diff --git a/assets/js/index.js b/assets/js/index.js index c771211..cc61f84 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,7 +1,3 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file -// This code was bundled using `deno bundle` and it's not recommended to edit it manually - (function() { const cookiesDisabled = !navigator.cookieEnabled; if (cookiesDisabled) { @@ -568,4 +564,4 @@ }, 1000); }); })(); -console.log("Surface Control: Complete"); +console.log("Surface Control: Complete"); \ No newline at end of file diff --git a/shell.nix b/shell.nix index 31ceb72..e002d79 100644 --- a/shell.nix +++ b/shell.nix @@ -39,6 +39,7 @@ let /usr/bin/env --ignore-environment /bin/sh -c ${ pkgs.writeScript name '' export PS1='\h (${name}) \W \$ ' + export DENO_DIR=vendor export PATH=${pkgs.lib.strings.makeBinPath [ hugo validatornu diff --git a/static/js/bundle.ts b/static/js/bundle.ts new file mode 100644 index 0000000..ac858c4 --- /dev/null +++ b/static/js/bundle.ts @@ -0,0 +1,21 @@ +import { bundle } from "https://deno.land/x/emit@0.17.0/mod.ts"; + +function removeSourceMap(text): string { + return text.replace(/^\/\/# sourceMappingURL.*$/gm, "").trim(); +} + +const entrypoint = await bundle( + "./static/js/index.ts", +); + +const output = removeSourceMap(entrypoint.code); +const file = Deno.cwd() + "/assets/js/index.js"; +const fileSize = ((await Deno.stat(file)).size / 1024).toFixed(2) + "kB"; + +await Deno.writeTextFile(file, output, {}); + +console.log( + `Bundle file:///${file}` + + "\n" + + `Emit file:///${file} (${fileSize})`, +); -- cgit v1.2.3