All checks were successful
check / check (push) Successful in 57s
The esbuild config had --external:preact which told the bundler to leave preact as a require() call instead of including it in the bundle. Since the SPA loads app.js directly in the browser (no CDN or import map for preact), the browser has no require() function and throws: Uncaught Error: Dynamic require of "preact" is not supported Fix: - Remove --external:preact from build.sh so preact is bundled into app.js - Add --format=esm to output proper ESM instead of IIFE with CJS shims - Update index.html to use <script type="module"> for ESM compatibility - Remove the fallback build command (no longer needed) - Rebuild dist/app.js with preact properly inlined closes #48
34 lines
685 B
Bash
Executable File
34 lines
685 B
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
cd "$(dirname "$0")"
|
|
|
|
# Install esbuild if not present
|
|
if ! command -v esbuild >/dev/null 2>&1; then
|
|
if command -v npx >/dev/null 2>&1; then
|
|
NPX="npx"
|
|
else
|
|
echo "esbuild not found. Install it: npm install -g esbuild"
|
|
exit 1
|
|
fi
|
|
else
|
|
NPX=""
|
|
fi
|
|
|
|
mkdir -p dist
|
|
|
|
# Build JS bundle — preact must be bundled (no CDN/external loader)
|
|
${NPX:+$NPX} esbuild src/app.jsx \
|
|
--bundle \
|
|
--minify \
|
|
--format=esm \
|
|
--jsx-factory=h \
|
|
--jsx-fragment=Fragment \
|
|
--define:process.env.NODE_ENV=\"production\" \
|
|
--outfile=dist/app.js
|
|
|
|
# Copy static files
|
|
cp src/index.html dist/index.html
|
|
cp src/style.css dist/style.css
|
|
|
|
echo "Build complete: web/dist/"
|