- 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>
68 lines
No EOL
1.8 KiB
JavaScript
Executable file
68 lines
No EOL
1.8 KiB
JavaScript
Executable file
#!/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(); |