mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
build: add client-side TypeScript compilation pipeline
Adds scripts/build-client.mjs which uses esbuild to compile TypeScript files in src/scripts/client/ into minified IIFE bundles, then writes them as TypeScript string-constant modules in src/scripts/generated/. - Adds build:client npm script; wires it as prebuild and predev hooks - Adds src/scripts/client/tsconfig.json with DOM lib for IDE support - Excludes src/scripts/client/ from the root Worker tsconfig to avoid DOM type conflicts with the Cloudflare Workers runtime types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
// Compiles client-side TypeScript files with esbuild and writes the result
|
||||
// as TypeScript string-constant modules importable by the Cloudflare Worker.
|
||||
|
||||
import { build } from 'esbuild';
|
||||
import { writeFileSync, mkdirSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const root = join(__dirname, '..');
|
||||
|
||||
const entries = [
|
||||
{
|
||||
input: 'src/scripts/client/dashboard.ts',
|
||||
exportName: 'dashboardScript',
|
||||
output: 'src/scripts/generated/dashboard.ts',
|
||||
},
|
||||
{
|
||||
input: 'src/scripts/client/emails-page.ts',
|
||||
exportName: 'emailsPageScript',
|
||||
output: 'src/scripts/generated/emails-page.ts',
|
||||
},
|
||||
];
|
||||
|
||||
mkdirSync(join(root, 'src/scripts/generated'), { recursive: true });
|
||||
|
||||
for (const { input, exportName, output } of entries) {
|
||||
const result = await build({
|
||||
entryPoints: [join(root, input)],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
write: false,
|
||||
target: 'es2020',
|
||||
platform: 'browser',
|
||||
format: 'iife',
|
||||
});
|
||||
|
||||
const code = new TextDecoder().decode(result.outputFiles[0].contents);
|
||||
const content = [
|
||||
'// AUTO-GENERATED by scripts/build-client.mjs — do not edit directly.',
|
||||
'// Source: ' + input,
|
||||
'// Run `npm run build:client` to regenerate.',
|
||||
'/* eslint-disable */',
|
||||
'export const ' + exportName + ' = ' + JSON.stringify(code) + ';',
|
||||
'',
|
||||
].join('\n');
|
||||
|
||||
writeFileSync(join(root, output), content);
|
||||
console.log('Built:', output);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2021", "DOM"],
|
||||
"types": [],
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["./**/*"],
|
||||
"exclude": []
|
||||
}
|
||||
+1
-1
@@ -17,5 +17,5 @@
|
||||
"jsxImportSource": "hono/jsx"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"exclude": ["node_modules", "dist", "src/scripts/client/**/*"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user