diff options
| author | eltrac <hi@eltr.ac> | 2026-10-07 20:17:40 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-08 15:10:11 +0800 |
| commit | bb2a06d10a85288319ec310d19d5f7c9a82b56af (patch) | |
| tree | a0e845265e7619aa97139099647f48484a997773 /bellsprout/scripts | |
| parent | add243af59b54daa642e862136bd6f60f3bb2609 (diff) | |
fe: add bb task that treeshakes pico.min.css
- add a bb task that uses PurgeCSS to treeshake pico.min.css
- add a bb task that cleanly builds Bellsprout
- use purged pico css in Bellsprout
- write docs about Bellsprout
Diffstat (limited to 'bellsprout/scripts')
| -rw-r--r-- | bellsprout/scripts/treeshake.clj | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/bellsprout/scripts/treeshake.clj b/bellsprout/scripts/treeshake.clj new file mode 100644 index 0000000..6e9a786 --- /dev/null +++ b/bellsprout/scripts/treeshake.clj @@ -0,0 +1,33 @@ +#!/usr/bin/env bb +(ns treeshake) + +(require '[babashka.tasks :refer [shell]]) +(require '[babashka.fs :as fs]) +(require '[cheshire.core :as json]) + +(defn treeshake [content original target] + (let [shake (partial shell {:out :string} + "purgecss" + "--css" original + "--content") + out (apply shake content) + css (-> out :out json/parse-string first (get "css"))] + (spit target css))) + +(def original-css "resources/public/css/pico.min.css") +(def target-css "resources/public/css/pico.purged.css") +(def html-file "resources/public/index.html") +(def js-file "src/bellsprout/core.cljs") + +(defn treeshake-pico [] + (treeshake [html-file js-file] original-css target-css) + (if (fs/exists? target-css) + (let [size #(.length (java.io.File. %)) + old-size (size original-css) + new-size (size target-css)] + (println "Tree shaken. Purged CSS file size:" new-size "Bytes" + (str "(" (- new-size old-size ) " Bytes)"))) + (println "Something went wrong."))) + +(defn -main [] + (treeshake-pico)) |
