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
Revive Tailwind CSS Compilation #246
Conversation
deps.edn
Outdated
@@ -25,8 +25,10 @@ | |||
org.babashka/cli {:mvn/version "0.5.40"}} | |||
:extra-paths ["notebooks"] | |||
:exec-fn nextjournal.clerk/build! | |||
:exec-args {:paths-fn nextjournal.clerk.builder/clerk-docs} | |||
:exec-args {:paths-fn nextjournal.clerk.builder/clerk-docs | |||
:compile-css? true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the ? here please, (like we did for bundle) we normalize this early
src/nextjournal/clerk/builder.clj
Outdated
@@ -78,6 +81,7 @@ | |||
(str "Errored in " duration ". ❌\n") | |||
(str "Done in " duration ". ✅\n")) | |||
:building (str "🔨 Building \"" (:file doc) "\"… ") | |||
:compiling-css "🎨 Optimizing CSS… " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiling Tailwind CSS…
src/nextjournal/clerk/builder.clj
Outdated
[{:keys [out-path]} docs] | ||
(assert (and (= 0 (:exit (sh "which" "npx"))) (= 0 (:exit (sh "npx" "tailwindcss")))) | ||
"Clerk's CSS optimizaiton failed: node and tailwind need to be installed. Please run `npm install -D tailwindcss @tailwindcss/typography` and retry.") | ||
(spit "tailwind.config.cjs" (slurp (io/resource "stylesheets/tailwind.config.js"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why .cjs and not .js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of type: module in the package.json. All .js files are treated like ES modules unless they have a .cjs extension.
src/nextjournal/clerk/builder.clj
Outdated
"--config" "tailwind.config.cjs" | ||
"--output" (str (fs/path out-path "viewer.css")) | ||
"--minify") | ||
(swap! config/!resource->url assoc "/css/viewer.css" "viewer.css")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should content address the css (like we do for the images) so the file name should be sha512.css
(defn include-viewer-css [] | ||
(defn relative? [url] | ||
(and (not (.isAbsolute (URI. url))) | ||
(not (str/starts-with? url "/")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are both of these checks needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because (= false (.isAbsolute (URI. "/viewer.css")))
Workflow
upload purged CSS to CAS (can we use dejavu ?)copy to out folderCASURL.API
If it's meant to be part of
build-static-app!
we could start by passing an:optimize-css-fn
option. The function is responsible for the whole workflow above except for the string replacement, and returns a stylesheet URL. We could handle the replacement on our side.Current Config
Prior Art
clerk
clerk/src/nextjournal/clerk.clj
Lines 357 to 366 in 914c310
nextjournal
https://github.com/nextjournal/nextjournal/blob/5a5f01ccb49a70885e272ef65db1589442345cad/ops/src/nextjournal/ops/build.clj#L25-L46