Skip to content

Instantly share code, notes, and snippets.

@olivergeorge
Last active May 22, 2021 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivergeorge/8a04740bd3402a19849c367d817dde49 to your computer and use it in GitHub Desktop.
Save olivergeorge/8a04740bd3402a19849c367d817dde49 to your computer and use it in GitHub Desktop.
Simple shadow-cljs example

After struggling with the clojurescript webpack setup I decided, finally, to try shadow cljs.

Baseline in this case was a clojurescript project using webpack as per the guide.

The project included a deps.edn file and package.json defining node modues we required.

A config file...

My minimal config file is below. Not complex but the doco fails the "quick start" test so it's possibly a handy reference for those who prefer to pattern match.

;; shadow-cljs configuration
{:deps   true
 :builds {:app {:target     :browser
                :modules    {:main {:entries [metcalf3.core]}}
                ;; NOTE: these are specific to my use case
                :output-dir "resources/public/js/dev"    
                :asset-path "/static/metcalf3/js/dev"
                :devtools   {:preloads [metcalf3.preload]}
                }}}

Things to note

  • We're deferring to deps.edn for dependencies
  • We're building for a browser environment

and a command line tool...

Shadow-cljs has a cli tool. To build I type shadow-cljs compile app.

https://shadow-cljs.github.io/docs/UsersGuide.html#_command_line

(Also helpful docs)

The documentation gives you a handy table to help clarify the translation of JS require statements to CLJS :require statements.

https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages

My personal advice is to stick with syntax with matches up with the "official" clojurescript compilers require statements (e.g. :default is not backward compatible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment