Skip to content

Instantly share code, notes, and snippets.

@Deraen
Created May 4, 2022 12:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deraen/695c94848d3ee05990239d403f7fe733 to your computer and use it in GitHub Desktop.
Save Deraen/695c94848d3ee05990239d403f7fe733 to your computer and use it in GitHub Desktop.
Shadow CLJS and Dart Sass
(ns app.dev.shadow
(:require [shadow.cljs.devtools.api :as shadow]
[clojure.edn :as edn]))
;; Run this with:
;; npx shadow-cljs clj-run app.dev.shadow/watch
(set! *warn-on-reflection* true)
(defn watch
{:shadow/requires-server true}
[& _args]
;; Both watches keep running until ctrl-c.
;; You could also call bash script here, so you could manage the Sass CLI options in one place for
;; both watch and release.
(let [cmd ["npx" "sass" "--watch"
"-I" "." ;; Optional: include project root as a Sass include path
"src/scss/:target/dev/public/css/"]
;; Redirect stdin to process, so ctrl-c is seen by sass.
;; Also redirect output to stdout.
builder (-> (ProcessBuilder. ^"[Ljava.lang.String;" (into-array String cmd))
(.inheritIO))
process (.start builder)]
;; Ctrl-c would close sass, but if shadow java process is just killed,
;; we need to also kill sass.
(.addShutdownHook (Runtime/getRuntime)
(Thread.
;; Fn is Runnable
(fn []
(.destroy process))))
(shadow/watch :app)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment