|
1 | 1 | # Digital Bazaar — Makefile |
2 | 2 | # Simplifies common development tasks |
3 | 3 |
|
4 | | -.PHONY: help install update assets images hero clean serve serve-drafts build setup-hooks prod-build |
| 4 | +.PHONY: help install update assets images hero clean serve serve-drafts build setup-hooks prod-build dev-lint dev-install-tools |
5 | 5 |
|
6 | 6 | # Homebrew Ruby paths (macOS) |
7 | 7 | RUBY_BIN := /opt/homebrew/opt/ruby/bin |
@@ -35,6 +35,8 @@ help: ## Show this help message |
35 | 35 | @echo " $(CYAN)serve-drafts$(RESET) Start server with drafts visible" |
36 | 36 | @echo " $(CYAN)build$(RESET) Build static site to _site/" |
37 | 37 | @echo " $(CYAN)setup-hooks$(RESET) Enable git pre-commit hooks" |
| 38 | + @echo " $(CYAN)dev-install-tools$(RESET) Install PurgeCSS for dead code detection" |
| 39 | + @echo " $(CYAN)dev-lint$(RESET) Find unused CSS (requires dev-install-tools)" |
38 | 40 | @echo "" |
39 | 41 | @echo "$(YELLOW)Production:$(RESET)" |
40 | 42 | @echo " $(CYAN)prod-build$(RESET) Build for production (minified)" |
@@ -147,6 +149,45 @@ serve: ## Start local development server at http://localhost:4000 |
147 | 149 | serve-drafts: ## Start server with draft posts visible |
148 | 150 | $(BUNDLE) exec jekyll serve --livereload --drafts |
149 | 151 |
|
| 152 | +dev-lint: ## Find unused CSS using PurgeCSS (requires: make dev-install-tools) |
| 153 | + @echo "🔍 Analyzing CSS for unused selectors..." |
| 154 | + @echo "" |
| 155 | + @if [ ! -d node_modules/purgecss ]; then \ |
| 156 | + echo "❌ PurgeCSS not installed. Run 'make dev-install-tools' first."; \ |
| 157 | + exit 1; \ |
| 158 | + fi |
| 159 | + @# Build the site first to get all HTML |
| 160 | + @$(BUNDLE) exec jekyll build --quiet |
| 161 | + @mkdir -p _site/purged |
| 162 | + @echo "Scanning _site/ for unused CSS..." |
| 163 | + @echo "" |
| 164 | + @npx purgecss \ |
| 165 | + --css _site/assets/css/styles.css \ |
| 166 | + --content '_site/**/*.html' \ |
| 167 | + --output _site/purged |
| 168 | + @echo "" |
| 169 | + @echo "$(YELLOW)Results:$(RESET)" |
| 170 | + @ORIG=$$(wc -c < _site/assets/css/styles.css | tr -d ' '); \ |
| 171 | + PURGED=$$(wc -c < _site/purged/styles.css | tr -d ' '); \ |
| 172 | + SAVED=$$((ORIG - PURGED)); \ |
| 173 | + echo " Original: $$ORIG bytes"; \ |
| 174 | + echo " Purged: $$PURGED bytes"; \ |
| 175 | + echo " Savings: $$SAVED bytes ($$(( (SAVED * 100) / ORIG ))%)" |
| 176 | + @echo "" |
| 177 | + @echo "$(YELLOW)Purged CSS saved to:$(RESET) _site/purged/styles.css" |
| 178 | + @echo "" |
| 179 | + @echo "💡 Compare _site/assets/css/styles.css with _site/purged/styles.css" |
| 180 | + @echo " to identify unused selectors, then manually remove from source." |
| 181 | + |
| 182 | +dev-install-tools: ## Install dead code detection tools (PurgeCSS) |
| 183 | + @echo "📦 Installing dead code detection tools..." |
| 184 | + @if [ ! -f package.json ]; then \ |
| 185 | + echo '{"name": "digitalbazaar-dev", "private": true}' > package.json; \ |
| 186 | + fi |
| 187 | + npm install --save-dev purgecss |
| 188 | + @echo "" |
| 189 | + @echo "✅ Tools installed. Run 'make dev-lint' to analyze CSS." |
| 190 | + |
150 | 191 | # ============================================================================= |
151 | 192 | # PRODUCTION |
152 | 193 | # ============================================================================= |
|
0 commit comments