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
This commit is contained in:
George Cushen committed 2025-09-25 21:51:54 +01:00
1 parent c843d01cf8
commit e9b31f8090
9 files changed
+12 -19

No files matched your search

+2 -2
View File
@@ -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(<HeroBlock {...props} />, block);
render(<HeroBlock {...props} />, block);
console.debug(`✓ Hero block "${block.id}" rendered with Preact`);
} catch (error) {
console.error(`Failed to render Hero block "${block.id}":`, error);
@@ -1,4 +1,4 @@
// Use classic JSX transform with global preact; no direct import
import {h} from "preact";
/**
* Icon component
@@ -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" }}
<script src="{{ $preact_core.RelPermalink }}" integrity="{{ $preact_core.Data.Integrity }}"></script>
{{/* 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" "")
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@tailwindcss/cli": "^4.1.12",
"@tailwindcss/typography": "^0.5.10",
"preact": "^10.27.2",
"tailwindcss": "^4.1.12"
}
}