From e9b31f8090c0962fb6645e1d29e46f0708676ff9 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Thu, 25 Sep 2025 21:51:52 +0100 Subject: [PATCH] refactor(preact): switch from vendored globals to bundled node_modules approach - Add preact dependency to all 6 starter package.json files for proper js.Build resolution - Use automatic JSX runtime (JSX: "automatic", JSXImportSource: "preact") in libraries.html - Restore proper ES module imports in hero/client.jsx and Icon.jsx components - Remove vendored preact script loading since preact is now bundled via js.Build - Fixes CI build failures with "Could not resolve preact/jsx-runtime" errors - Provides cleaner, more standard JS tooling for users extending with custom components BREAKING CHANGE: Starters now require `preact` in `package.json`to resolve preact dependency before hugo build --- modules/blox-tailwind/blox/hero/client.jsx | 4 ++-- .../blox/shared/js/components/Icon.jsx | 2 +- .../layouts/_partials/libraries.html | 19 +++---------------- starters/academic-cv/package.json | 1 + starters/blog/package.json | 1 + starters/documentation/package.json | 1 + starters/landing-page/package.json | 1 + starters/link-in-bio/package.json | 1 + starters/resume/package.json | 1 + 9 files changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/blox-tailwind/blox/hero/client.jsx b/modules/blox-tailwind/blox/hero/client.jsx index b8de2092..3e2c0bb6 100644 --- a/modules/blox-tailwind/blox/hero/client.jsx +++ b/modules/blox-tailwind/blox/hero/client.jsx @@ -3,7 +3,7 @@ * Uses the shared component for consistency */ -// Use global preact (loaded via script tag) with classic JSX transform +import {render} from "preact"; import {HeroBlock} from "./component.jsx"; // Render function - immediately renders Hero components @@ -18,7 +18,7 @@ function renderHeroBlocks() { const props = JSON.parse(propsData); // Render the Preact component into the container - preact.render(, block); + render(, block); console.debug(`✓ Hero block "${block.id}" rendered with Preact`); } catch (error) { console.error(`Failed to render Hero block "${block.id}":`, error); diff --git a/modules/blox-tailwind/blox/shared/js/components/Icon.jsx b/modules/blox-tailwind/blox/shared/js/components/Icon.jsx index 8b2573b3..4d4656cf 100644 --- a/modules/blox-tailwind/blox/shared/js/components/Icon.jsx +++ b/modules/blox-tailwind/blox/shared/js/components/Icon.jsx @@ -1,4 +1,4 @@ -// Use classic JSX transform with global preact; no direct import +import {h} from "preact"; /** * Icon component diff --git a/modules/blox-tailwind/layouts/_partials/libraries.html b/modules/blox-tailwind/layouts/_partials/libraries.html index 63c1e886..96f32b01 100644 --- a/modules/blox-tailwind/layouts/_partials/libraries.html +++ b/modules/blox-tailwind/layouts/_partials/libraries.html @@ -3,19 +3,7 @@ {{ if .Page.Store.Get "needs_preact" }} {{ $preact_blocks := .Page.Store.Get "preact_blocks" | default slice }} - {{/* Load Preact core library */}} - {{ $preact_core := resources.Get "dist/lib/preact/preact.min.js" }} - {{ if $preact_core }} - {{ $preact_core = $preact_core | resources.Fingerprint "sha256" }} - - - {{/* Publish the source map so the browser can load it at the expected path */}} - {{ $preact_map := resources.Get "dist/lib/preact/preact.min.js.map" }} - {{ if $preact_map }} - {{ $preact_map.Publish }} - {{ end }} - - {{ end }} + {{/* Preact is now bundled with each template via js.Build and node_modules */}} {{/* Build and load each Preact block's client script */}} {{ range $block_type := $preact_blocks }} @@ -26,9 +14,8 @@ {{/* Build the client-side JSX using Hugo's official integration */}} {{ $jsx_opts := dict "targetPath" (printf "assets/js/preact-built/%s.js" $block_type) - "JSX" "transform" - "JSXFactory" "preact.h" - "JSXFragment" "preact.Fragment" + "JSX" "automatic" + "JSXImportSource" "preact" "format" "iife" "minify" hugo.IsProduction "sourceMap" (cond hugo.IsDevelopment "external" "") diff --git a/starters/academic-cv/package.json b/starters/academic-cv/package.json index 1286a95a..cecc8b29 100644 --- a/starters/academic-cv/package.json +++ b/starters/academic-cv/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } } diff --git a/starters/blog/package.json b/starters/blog/package.json index f19f822e..5067328a 100644 --- a/starters/blog/package.json +++ b/starters/blog/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } } diff --git a/starters/documentation/package.json b/starters/documentation/package.json index f24abaf3..7334727f 100644 --- a/starters/documentation/package.json +++ b/starters/documentation/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } } diff --git a/starters/landing-page/package.json b/starters/landing-page/package.json index e29850bf..bd292835 100644 --- a/starters/landing-page/package.json +++ b/starters/landing-page/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } } diff --git a/starters/link-in-bio/package.json b/starters/link-in-bio/package.json index c42fdf75..5cfb5c2b 100644 --- a/starters/link-in-bio/package.json +++ b/starters/link-in-bio/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } } diff --git a/starters/resume/package.json b/starters/resume/package.json index bf921297..69dd89e2 100644 --- a/starters/resume/package.json +++ b/starters/resume/package.json @@ -11,6 +11,7 @@ "dependencies": { "@tailwindcss/cli": "^4.1.12", "@tailwindcss/typography": "^0.5.10", + "preact": "^10.27.2", "tailwindcss": "^4.1.12" } }