Bootstraps the shared frontend build glue for webapp-template-derived projects: bin/fetch-openapi.sh — pull Swagger JSON from a running backend bin/postprocess-openapi.py — fix oatpp 1.3 rough edges before orval bin/inject-hashed-filenames.py — rewrite HTML tags, config-driven src/vite-config.ts — defineAdminConfig / defineGuestConfig templates/orval.config.template.ts — starting point for derived repos Package name @uschuster/webapp-scaffold. Consumed as a devDependency through the internal Forgejo npm registry; binaries exposed for use in package.json scripts. createCoreFetch + i18n deferred to v0.2 / v0.3. Closes fewo-webapp#414 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
// Vite config factories shared across webapp-template-derived projects.
|
|
//
|
|
// Derived projects typically have two bundles:
|
|
// - the admin / owner SPA (`defineAdminConfig`)
|
|
// - the public guest site (`defineGuestConfig`)
|
|
// Both honour the same Apache-proxy-prefix baseUrl convention and keep
|
|
// their outputs under a conventional path so the `StaticController` and
|
|
// Apache vhost can serve them without per-project tweaks.
|
|
|
|
import type { UserConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'path';
|
|
|
|
export interface AdminConfigOptions {
|
|
/** Directory the vite.config.ts lives in — pass `__dirname` or `import.meta.dirname`. */
|
|
root: string;
|
|
/** Optional manual chunks for large vendor libs. */
|
|
vendorChunks?: Record<string, string[]>;
|
|
/** Override the default output dir (default: `<root>/../static/dist`). */
|
|
outDir?: string;
|
|
}
|
|
|
|
export function defineAdminConfig(opts: AdminConfigOptions): UserConfig {
|
|
const base = process.env.VITE_BASE || '/';
|
|
return {
|
|
base,
|
|
plugins: [react()],
|
|
build: {
|
|
outDir: opts.outDir ?? path.resolve(opts.root, '../static/dist'),
|
|
emptyOutDir: true,
|
|
manifest: true,
|
|
rollupOptions: opts.vendorChunks
|
|
? { output: { manualChunks: opts.vendorChunks } }
|
|
: undefined,
|
|
},
|
|
};
|
|
}
|
|
|
|
export interface GuestConfigOptions extends AdminConfigOptions {
|
|
/** Entry point relative to root (default: `src/guest/main.tsx`). */
|
|
entry?: string;
|
|
}
|
|
|
|
export function defineGuestConfig(opts: GuestConfigOptions): UserConfig {
|
|
const base = process.env.VITE_BASE || '/';
|
|
return {
|
|
base,
|
|
plugins: [react()],
|
|
build: {
|
|
outDir: opts.outDir ?? path.resolve(opts.root, '../static/guest/dist'),
|
|
emptyOutDir: true,
|
|
manifest: true,
|
|
rollupOptions: {
|
|
input: path.resolve(opts.root, opts.entry ?? 'src/guest/main.tsx'),
|
|
output: {
|
|
entryFileNames: 'guest-app.[hash].js',
|
|
chunkFileNames: 'guest-chunk-[hash].js',
|
|
assetFileNames: 'guest-asset-[hash][extname]',
|
|
manualChunks: opts.vendorChunks,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|