Fork me on GitHub
#shadow-cljs
<
2021-03-13
>
wombawomba16:03:56

is there a recommended way of running other background processes (asset processors, static site builders etc) together with shadow-cljs watch?

wombawomba18:03:31

FWIW I found https://www.npmjs.com/package/concurrently which seems works really nicely for my use-case

thheller16:03:57

nowadays I just run things separately

wombawomba16:03:11

alright, thanks!

stopa17:03:43

Hey team, is there a recommended article / resource, that goes into the “most idiomatic setup” for css with shadow? Would love any pointers!

stopa18:03:12

Hey team, I am playing around with optimizing my shadow-cljs bundle. I ran

npx shadow-cljs run shadow.cljs.build-report app report.html 
One thing I noticed, is that currently the clojurescript runtime is taking 400kb. That seems surprising — I thought it would be doing some kind of tree-shaking. (To test, I deleted all code in core.cljs, and left the imports) Here’s my shadow config in project.clj:
{:nrepl {:port 7002}
   :builds
   {:app
    {:target :browser
     :output-dir "target/cljsbuild/public/js"
     :asset-path "/js"
     :modules {:app {:entries []}}
     :dev {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}
     :devtools {:preloads [day8.re-frame-10x.preload]
                :watch-dir "resources/public"}}
    :test
    {:target :node-test
     :output-to "target/test/test.js"
     :autorun true}}}
I may be missing something trivial. (perhaps I need to manually set a certain kind of :optimizations? Any pointers / resources for debugging further would be appreciated!

thheller18:03:43

you are including cljs.analzyer and cljs.pprint somewhere

thheller18:03:57

those are very heavy hitters that can't be DCE'd

thheller18:03:11

so you should get rid of those at least (which will also further shrink cljs.core in the process)

stopa18:03:48

Ah, thanks for the pointer @thheller! Will look deeper.

stopa18:03:19

Okay, looks like the two biggers culprits: I have a /dev/…/app.cljs file, which imports

[cljs.spec.alpha :as s]
    [expound.alpha :as expound]
    [devtools.core :as devtools]))
And my core.cljs file imported [reitit.coercion.spec :as reitit-spec], which seem to also be a culprit. My guess right now is that I am incorrectly using /dev/ vs /prod/, and then will learn more about what reitit-spec is about.

thheller18:03:09

devtools.core you should remove unless you are calling it somewhere directly?

thheller18:03:59

dev stuff in general you want to move into a :preloads ns

stopa19:03:30

Right now, the way it is set up, I have a custom file in /env/dev/cljs/[app-name]/app.cljs , which does the following:

(ns ^:dev/once 
  (:require
    [virtual-library.core :as core]
    [cljs.spec.alpha :as s]
    [expound.alpha :as expound]
    [devtools.core :as devtools]))

(extend-protocol IPrintWithWriter
  js/Symbol
  (-pr-writer [sym writer _]
    (-write writer (str "\"" (.toString sym) "\""))))

(set! s/*explain-out* expound/printer)

(enable-console-print!)

(devtools/install!)

(core/init!)
Looking at project.clj, looks like this gets replaced by a /prod/ in uberjar:
{:uberjar {:omit-source true
             :prep-tasks ["compile" ["shadow" "release" "app"]]

             :aot :all
             :uberjar-name "virtual-library.jar"
             :source-paths ["env/prod/clj"  "env/prod/cljs" ]
             :resource-paths ["env/prod/resources"]}
I think the way I set up shadow, the reporting script is assuming env/dev/*. Will look deeper into this, and :preloads. From a quick test, looks like this is indeed what is happening,

thheller19:03:20

this is a terrible pattern I would strongly recommend changing

thheller19:03:07

in your build config set :modules {:app {:init-fn ! :preloads [virtual-library.dev]}}

thheller19:03:18

and move all the stuff you have in app to the .dev ns

thheller19:03:30

no need to switch the classpath and all that mess

thheller19:03:50

(enable-console-print!)

(devtools/install!)

(core/init!)

thheller19:03:58

delete these 3 too. not needed at all.

stopa19:03:30

…Amaazing! Thank you @thheller!

stopa19:03:30

Also, with reitit-spec removed, and the dev/app stuff, now we’re muuch better: (will update with your advice and keep playing with the optimization)

stopa19:03:13

Okay, current shadow setup:

{:nrepl {:port 7002}
   :builds
   {:app
    {:target :browser
     :output-dir "target/cljsbuild/public/js"
     :asset-path "/js"
     :modules {:app {:init-fn virtual-library.core/init! :preloads [virtual-library.dev]}}
     :dev {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}
     :devtools {:preloads [day8.re-frame-10x.preload]
                :watch-dir "resources/public"}}
    :test
    {:target :node-test
     :output-to "target/test/test.js"
     :autorun true}}}
first thought, will try moving day8.re-frame-10x.preload into virtual-library.dev . Let me know if there’s more cleanup I could do : } — thanks team

thheller21:03:30

fine to just move :preloads together. either in :modules or :devtools is fine

❤️ 3