Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Without hooks #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "uix-starter",
"scripts": {
"dev": "shadow-cljs -A:dev watch app & yarn styles-dev",
"release": "shadow-cljs -A:dev release app && yarn styles-release",
"dev": "shadow-cljs -A:dev run dev.build/start & yarn styles-dev",
"release": "shadow-cljs -A:dev run dev.build/release && yarn styles-release",
"styles-dev": "onchange -o '> public/main.css && lightningcss --bundle public/main.css -o public/main.css' -i src/**/*.css -- cat src/**/*.css",
"styles-release": "cat src/**/*.css > public/main.css && lightningcss --minify --bundle public/main.css -o public/main.css",
"start:libs": "mkdir -p target/gen && touch target/gen/libs.js && node watch.mjs",
"start:libs": "node watch.mjs",
"build:libs": "node build.mjs"
},
"dependencies": {
Expand Down
9 changes: 2 additions & 7 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
:js-options {:js-provider :external
:external-index "target/gen/libs.js"
:external-index-format :esm}
:release {:build-hooks [;; Esbuild must run after shadow-cljs flush so no way to optimize.
;; You can replace yarn with npm.
(dev.build/run-cmd-flush {:cmd ["yarn" "build:libs"]
:once true})]
;; If you want to enable module-hash-names you need to fix the references in the index.html to refer to
:release {;; If you want to enable module-hash-names you need to fix the references in the index.html to refer to
;; the new names.
;; ESBuild can also enable this.
;; Shadow-cljs would write information about created output files in public/js/manifest.edn and ESBuild in
;; public/js/manifest.json (if you enable that in build.mjs)
;; :module-hash-names true
}
:dev {:build-hooks [(dev.build/run-cmd-configure {:cmd ["yarn" "start:libs"]})]}}}}
}}}}
24 changes: 23 additions & 1 deletion src/dev/build.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns dev.build)
(ns dev.build
(:require [shadow.cljs.devtools.api :as shadow]))

(defn start-process [cmd]
(let [;; Redirect output to stdout.
Expand All @@ -11,6 +12,27 @@
(.addShutdownHook (Runtime/getRuntime) (Thread. (fn [] (.destroy process))))
process))

;; New version - main function

(defn start
{:shadow/requires-server true}
[& _args]
;; Watch call blocks until the first build is done -> the index file
;; will be available when ESBuild is started
(shadow/watch :app)
(start-process ["yarn" "start:libs"])
::started)

(defn release
[]
(shadow/release :app)
(.waitFor (start-process ["yarn" "build:libs"])))

;; Old version - hooks

;; TODO: Hooks might run multiple times, for example if the shadow-cljs.edn is changed
;; -> multiple ESBuild processes
;; Consider "main ns" to run the process & Shadow-cljs, so no need for hooks?
(defn run-cmd-configure
{:shadow.build/stage :configure}
[build-state {:keys [cmd]}]
Expand Down