From ac7c562a2d5f30493466bf7db02d9e268a5633d6 Mon Sep 17 00:00:00 2001 From: Jcparkyn <51850908+Jcparkyn@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:51:35 +0000 Subject: [PATCH] Add minification for elm.js --- .devcontainer/Dockerfile | 1 + .github/workflows/main.yml | 4 ++-- .gitignore | 1 + .vscode/tasks.json | 2 +- optimize.sh | 16 ++++++++++++++++ public/index.html | 2 +- 6 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 optimize.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4133da1..70c47e3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -19,6 +19,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ elm-test@${ELM_TEST_VERSION} \ elm-format@${ELM_FORMAT_VERSION} \ elm-live@${ELM_LIVE_VERSION} \ + uglify-js@3.18.0 \ # # [Optional] Update UID/GID if needed && if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f80b335..f63040b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,9 +27,9 @@ jobs: uses: actions/setup-node@v3 with: node-version: "18" - - run: npm install -g elm + - run: npm install -g elm@latest-0.19.1 uglify-js@3.18.0 - name: make - run: elm make src/Main.elm --output=public/main.js + run: ./optimize.sh src/Main.elm - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/.gitignore b/.gitignore index a182187..5109ed1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ elm-stuff elm.js +elm.min.js main.js \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fd10e91..fdac1c0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "start dev server", "type": "shell", - "command": "elm-live src/Main.elm --dir=./public -- --output=public/main.js", + "command": "elm-live src/Main.elm --dir=./public -- --output=public/elm.js", "problemMatcher": [], "group": { "kind": "build", diff --git a/optimize.sh b/optimize.sh new file mode 100755 index 0000000..85e5f19 --- /dev/null +++ b/optimize.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +js="public/elm.js" +min="public/elm.min.js" + +elm make --optimize --output=$js "$@" + +uglifyjs $js --compress 'pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output $min + +echo "Compiled size:$(wc $js -c) bytes ($js)" +echo "Minified size:$(wc $min -c) bytes ($min)" +echo "Gzipped size: $(gzip $min -c | wc -c) bytes" + +cp $min $js diff --git a/public/index.html b/public/index.html index c03bdb3..519b514 100644 --- a/public/index.html +++ b/public/index.html @@ -6,7 +6,7 @@ - +