Replace Tailwind CSS CDN with Vite build#298
Closed
andriytyurnikov wants to merge 1 commit intoredplanetlabs:masterfrom
Closed
Replace Tailwind CSS CDN with Vite build#298andriytyurnikov wants to merge 1 commit intoredplanetlabs:masterfrom
andriytyurnikov wants to merge 1 commit intoredplanetlabs:masterfrom
Conversation
e2b3638 to
48e6f28
Compare
Use Vite with @tailwindcss/vite to compile CSS at build time instead of loading the ~100KB Tailwind browser runtime from CDN on every page. - vite.config.js: Tailwind plugin, content-hashed CSS output + manifest - dev/vite_hook.clj: shadow-cljs hook runs `vite build` automatically - server.clj: reads Vite JSON manifest for hashed CSS filename - build-ui.sh: runs `npx vite build` before shadow-cljs release No workflow change — shadow-cljs watch/compile triggers Vite via hook.
48e6f28 to
7d1fb24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
@tailwindcss/browserCDN runtime with build-time CSS compilation using Vite and@tailwindcss/vite.Supersedes #282 (which used custom shadow-cljs build hooks and was reverted in e080856).
Why
The browser runtime generates CSS at page load:
@layer,@apply, or pluginsApproach: Vite instead of shadow-cljs hooks
The previous attempt (#282) used a custom Clojure namespace (
tailwind_hook.clj) to shell out to the Tailwind CLI from shadow-cljs build hooks. This required managing child processes, shutdown hooks, and had race conditions on one-shot builds.This PR uses Vite — an industry-standard build tool with first-class Tailwind support. No custom process management code. The CSS build is a standard
npx vite buildcommand, completely independent of shadow-cljs.tailwind_hook.cljnpx vite build --watchnpx @tailwindcss/clivia Clojure shellingnpx vite buildWhat changed
vite.config.js@tailwindcss/viteplugin, outputs hashed CSS + JSON manifest toresource/public/src/cljs/.../ui/css/main.css@import "tailwindcss"+@sourcedirectiveresource/index.html{{MAIN_CSS}}placeholderserver.cljcss-tagreads Vite JSON manifest for hashed filename; falls back to CDN when no compiled CSS existsscripts/build-ui.shnpx vite buildbefore shadow-cljs releasepackage.jsonviteand@tailwindcss/vitedev dependencies.gitignoreshadow-cljs.ednCDN fallback for REPL workflow
The server checks for compiled CSS at request time. If found, serves
<link>to the hashed file. If not (e.g., REPL started without a prior build), falls back to the original CDN<script>tag. The REPL workflow ((aor/start-ui ipc)) continues to work with zero setup.Developer workflows
Test plan
npx vite build— producesmain.HASH.css(39KB) +css-manifest.jsonin 1.9snpx shadow-cljs compile :dev— unaffected, builds normallyscripts/build-ui.sh— produces both hashed CSS and JS