Add TypeScript frontend build system with shared components
- Set up esbuild for fast TypeScript compilation of frontend code - Create SharedHeader component with factories for main/admin/privacy pages - Create SharedFooter component with standard and minimal variants - Add frontend build scripts (build:frontend, watch:frontend, dev:full) - Configure TypeScript for browser environment with DOM types - Add example page demonstrating shared component usage - Update .gitignore to exclude compiled frontend files Benefits: - Type-safe frontend components - Consistent headers/footers across all pages - Single source of truth for common UI elements - Built-in i18n and theme toggle support 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7bee175003
commit
5151e87824
11 changed files with 986 additions and 4 deletions
68
scripts/build-frontend.js
Executable file
68
scripts/build-frontend.js
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const esbuild = require('esbuild');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Ensure output directory exists
|
||||
const outdir = path.join(__dirname, '..', 'public', 'dist');
|
||||
if (!fs.existsSync(outdir)) {
|
||||
fs.mkdirSync(outdir, { recursive: true });
|
||||
}
|
||||
|
||||
// Build configuration
|
||||
const buildOptions = {
|
||||
entryPoints: [
|
||||
// Main app bundles
|
||||
'src/frontend/app-main.ts',
|
||||
'src/frontend/app-admin.ts',
|
||||
'src/frontend/app-privacy.ts',
|
||||
|
||||
// Shared components will be imported by the above
|
||||
],
|
||||
bundle: true,
|
||||
outdir: outdir,
|
||||
format: 'iife', // Immediately Invoked Function Expression for browsers
|
||||
platform: 'browser',
|
||||
target: ['es2020'], // Modern browsers, matching our TypeScript target
|
||||
sourcemap: process.env.NODE_ENV !== 'production',
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
loader: {
|
||||
'.ts': 'ts',
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
|
||||
},
|
||||
// Don't bundle these - they'll be loaded from CDN
|
||||
external: ['leaflet'],
|
||||
};
|
||||
|
||||
// Build function
|
||||
async function build() {
|
||||
const isWatch = process.argv.includes('--watch');
|
||||
|
||||
try {
|
||||
if (isWatch) {
|
||||
// Watch mode for development
|
||||
const ctx = await esbuild.context(buildOptions);
|
||||
await ctx.watch();
|
||||
console.log('👀 Watching for frontend changes...');
|
||||
} else {
|
||||
// One-time build
|
||||
console.log('🔨 Building frontend...');
|
||||
const result = await esbuild.build(buildOptions);
|
||||
console.log('✅ Frontend build complete!');
|
||||
|
||||
if (result.errors.length > 0) {
|
||||
console.error('❌ Build errors:', result.errors);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Build failed:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the build
|
||||
build();
|
Loading…
Add table
Add a link
Reference in a new issue