Embedded the frontend in the binary, and built it in the build script
`npm run sync` in web/ copies the build output (web/dist, from npm run build) to internal/frontend/dist, which the binary embeds. Go can't embed from outside the package's directory (web/ is also outside the Go module), hence the copy. Only dist/.gitkeep is committed, so a fresh clone still compiles, and a binary built without syncing first serves no frontend. job-search serve serves server.frontend.dir if it is set, or else the embedded build, or warns that there is no frontend. scripts/build.sh builds and syncs the frontend before building, running npm ci first for a release or when web/node_modules is missing.
This commit is contained in:
1 parent
1832ea7437
commit
5e6c011ecb
12 files changed
+104
-11
No files matched your search
@@ -15,7 +15,8 @@ npm run lint # eslint .
|
||||
npm run format:check # prettier --check .
|
||||
npm run format # prettier --write .: formats every file
|
||||
npm run generate:api # regenerate src/types/api.ts from the backend's OpenAPI description
|
||||
npm run build # typecheck, then vite build
|
||||
npm run build # typecheck, then vite build into dist/
|
||||
npm run sync # copy dist/ to ../internal/frontend/dist/, which the backend embeds
|
||||
npm run dev # dev server; /api and /ws go to the backend (API_PROXY_TARGET, default localhost:9393)
|
||||
```
|
||||
|
||||
@@ -79,7 +80,7 @@ if (isRelease(parsed)) { ... }
|
||||
| `src/primitives/` | Solid primitives: state and loading, no markup (`createX.ts`) |
|
||||
| `src/components/` | Components, one exported component per file |
|
||||
| `src/lib/` | Plain functions: no Solid, no DOM where avoidable |
|
||||
| `scripts/` | Development scripts run by npm, in TypeScript (`generateApiTypes.ts`) |
|
||||
| `scripts/` | Development scripts run by npm, in TypeScript (`generateApiTypes.ts`, `syncDist.ts`) |
|
||||
|
||||
- Components' files are PascalCase, named after the component
|
||||
(`MarkMenu.tsx`). Other files are usually camelCase (`format.ts`); the
|
||||
|
||||
@@ -14,6 +14,10 @@ default address (`http://localhost:9393`). To use another, copy `.env.example`
|
||||
to `.env` and set `API_PROXY_TARGET`. `VITE_API_BASE_URL` changes the `/api`
|
||||
prefix for production builds.
|
||||
|
||||
`npm run build` type-checks and builds the app into `dist/`. `npm run sync`
|
||||
then copies `dist/` to `../internal/frontend/dist/`, where the backend embeds
|
||||
it: the next Go build of `job-search` serves it. The copy isn't committed.
|
||||
|
||||
Before committing, `npm run check` type-checks, lints (ESLint) and checks
|
||||
formatting (Prettier); `npm run format` formats everything. See
|
||||
[CODE_CONVENTIONS.md](CODE_CONVENTIONS.md).
|
||||
|
||||
+2
-1
@@ -12,7 +12,8 @@
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"check": "npm run typecheck && npm run lint && npm run format:check",
|
||||
"generate:api": "node scripts/generateApiTypes.ts"
|
||||
"generate:api": "node scripts/generateApiTypes.ts",
|
||||
"sync": "node scripts/syncDist.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"solid-js": "^1.9.3"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copies the frontend's build output, dist/ (from npm run build), to
|
||||
// ../internal/frontend/dist/, which the backend embeds, so the next Go build
|
||||
// of job-search serves this frontend:
|
||||
//
|
||||
// npm run build && npm run sync
|
||||
//
|
||||
// The old copy is replaced entirely, so files from an earlier build don't
|
||||
// linger. Its .gitkeep, the only file there that's committed, is put back:
|
||||
// Go can't embed a directory that doesn't exist.
|
||||
import { cpSync, existsSync, rmSync, writeFileSync } from 'node:fs';
|
||||
|
||||
const source = 'dist';
|
||||
const target = '../internal/frontend/dist';
|
||||
|
||||
if (!existsSync(`${source}/index.html`)) {
|
||||
console.error(`${source}/index.html not found: run npm run build first`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
rmSync(target, { recursive: true, force: true });
|
||||
cpSync(source, target, { recursive: true });
|
||||
writeFileSync(`${target}/.gitkeep`, '');
|
||||
|
||||
console.log(`Copied ${source}/ to ${target}/`);
|
||||
Reference in new issue
Block a user