├── .gitignore ├── yarn.lock ├── CHANGELOG.md ├── package.json ├── LICENSE ├── src └── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/ 3 | 4 | node_modules/.yarn-integrity 5 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 1.0.3 4 | Tidy up (thanks [@dpassen](https://github.com/dpassen)) 5 | 6 | ## 1.0.2 7 | Add support for Hiccup dot-syntax (`:div.h-full.overflow-hidden`) 8 | 9 | ## 1.0.1 10 | Correct links in `package.json` 11 | 12 | ## 1.0.0 13 | Initial release -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@multiplyco/tailwind-clj", 3 | "version": "1.0.3", 4 | "description": "Scan Clojure files for matches to Tailwind CSS class names.", 5 | "main": "src/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/multiplyco/tailwind-clj.git" 9 | }, 10 | "author": "Henrik Eneroth", 11 | "license": "MIT", 12 | "private": false, 13 | "bugs": { 14 | "url": "https://github.com/multiplyco/tailwind-clj/issues" 15 | }, 16 | "homepage": "https://github.com/multiplyco/tailwind-clj#readme", 17 | "keywords": ["clojure", "tailwind", "css"] 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Multiply 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const isString = (value) => typeof value === 'string' || value instanceof String; 2 | 3 | const scanClojure = (content) => { 4 | const a = []; 5 | 6 | // Match keyword classes 7 | const keywordMatches = content.matchAll(/:([^\s\])]+)/g); 8 | for (const match of keywordMatches) { 9 | const res = match[1]; 10 | 11 | a.push(res); 12 | 13 | if (isString(res)) { 14 | const splitMatch = res.match(/[^.]+/g) 15 | 16 | for (const n in splitMatch) { 17 | const w = splitMatch[n]; 18 | a.push(w); 19 | } 20 | } 21 | } 22 | 23 | // Match string classes 24 | const stringMatches = content.matchAll(/"([^"]+?)"/g); 25 | for (const match of stringMatches) { 26 | const res = match[1]; 27 | 28 | if (isString(res)) { 29 | const splitMatch = res.match(/\S+/g) 30 | 31 | for (const n in splitMatch) { 32 | const w = splitMatch[n]; 33 | a.push(w); 34 | } 35 | } 36 | } 37 | 38 | return a; 39 | } 40 | 41 | module.exports = {scanClojure}; 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tailwind-clj 2 | 3 | ## What? 4 | Scans Clojure source files for matches to Tailwind CSS class names. It will include matches for both strings and keywords. 5 | 6 | It does so quickly and correctly. 7 | 8 | ## Why? 9 | 10 | We started using Tailwind back in 2019, when it was hovering around 1.0. Initially it worked well, but occasionally 11 | it wouldn't pick up certain styles from the source files. This also changed between versions of Tailwind over the years. 12 | 13 | In order to get more predictable and correct results, we started extracting classes from the JS output rather than 14 | the Clojure source files. This worked fairly well up to the point where our app grew such that each Tailwind 15 | recompile took 20-30 seconds because of the size of the ClojureScript compiler JS output during dev time. 16 | 17 | This is a small library that fixes these problems. It, 18 | - Picks up all styles. 19 | - Completes a recompile in around 200-400ms as opposed to the previous 20-30 seconds. 20 | - Provides some measure of insulation against changes in Tailwind in regard to the scan logic. 21 | 22 | If you happen to be using a subset of Tailwind that doesn't break in Clojure, you probably don't need this library. 23 | If you have trouble with Tailwind picking up styles, or compiles taking a long time, it might help. 24 | 25 | ## How? 26 | 27 | E.g., 28 | ``` 29 | yarn add @multiplyco/tailwind-clj 30 | ``` 31 | 32 | In your `tailwind.config.js`: 33 | 34 | ``` 35 | const {scanClojure} = require('@multiplyco/tailwind-clj'); 36 | 37 | module.exports = { 38 | content: { 39 | files: [ 40 | './src/**/*.{clj,cljs,cljc}' 41 | ], 42 | extract: { 43 | clj: (content) => scanClojure(content), 44 | cljs: (content) => scanClojure(content), 45 | cljc: (content) => scanClojure(content) 46 | } 47 | }, 48 | 49 | … 50 | ``` --------------------------------------------------------------------------------