The src/index.html / src/stats.html files reference assets at URLs
like /static/app.js, /static/dashboard.css. The initial Phase 1 build
flattened everything to dist/{app.js, dashboard.css, ...} which would
have forced the Phase 4 Rust ServeDir mount to do URL rewriting just
to make the existing HTML references resolve.
Rework: bundles now write to dist/static/, HTML stays at dist/ top
level. Layout matches the URLs the HTML uses, so the Phase 4 mount
is the simplest possible `fallback_service(ServeDir::new(dist))`.
No source-file changes — just the esbuild outfile/outdir paths.
Rebuilt; verified asset filenames + sizes unchanged.
Refs #273.
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
// esbuild build for @hive/dashboard. Output layout (`dist/`):
|
|
//
|
|
// dist/index.html served by the Rust router at GET /
|
|
// dist/static/app.js served at /static/app.js (ESM bundle,
|
|
// pulls in @hive/shared + marked)
|
|
// dist/static/app.js.map source map sibling
|
|
// dist/static/dashboard.css served at /static/dashboard.css
|
|
// (@import resolved from @hive/shared)
|
|
//
|
|
// The Rust binary mounts `dist/` as a `tower_http::ServeDir` fallback;
|
|
// the layout above keeps every URL the index.html references reachable
|
|
// without rewriting paths in the HTML.
|
|
|
|
import { build } from 'esbuild';
|
|
import { mkdirSync, copyFileSync, rmSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const src = (p) => resolve(here, 'src', p);
|
|
const dist = (p) => resolve(here, 'dist', p);
|
|
const staticDir = (p) => resolve(here, 'dist', 'static', p);
|
|
|
|
rmSync(dist(''), { recursive: true, force: true });
|
|
mkdirSync(staticDir(''), { recursive: true });
|
|
|
|
// Bundle the JS entry. ES-module output, browser target, no minify
|
|
// (line-aligned source aids debugging; minification belongs in a later
|
|
// follow-up once asset sizes warrant it).
|
|
await build({
|
|
entryPoints: [src('app.js')],
|
|
outfile: staticDir('app.js'),
|
|
bundle: true,
|
|
format: 'esm',
|
|
platform: 'browser',
|
|
target: ['es2022'],
|
|
sourcemap: true,
|
|
logLevel: 'info',
|
|
});
|
|
|
|
// Bundle the CSS — esbuild resolves @import including the package
|
|
// re-exports from @hive/shared.
|
|
await build({
|
|
entryPoints: [src('dashboard.css')],
|
|
outfile: staticDir('dashboard.css'),
|
|
bundle: true,
|
|
loader: { '.css': 'css' },
|
|
logLevel: 'info',
|
|
});
|
|
|
|
copyFileSync(src('index.html'), dist('index.html'));
|
|
|
|
console.log('dashboard build ok →', dist(''));
|