80c2aa0401
The esbuild outdir was relative to cwd, so it landed at project root (dist/content/) on a project-root build, not under the extension dir. Fix: - esbuild writes to extension/dist/content/ - manifest.json content_scripts.js → dist/content/index.js - Keeps the extension self-contained so Chrome --load-extension works without any external files
32 lines
929 B
JavaScript
32 lines
929 B
JavaScript
// esbuild config — bundles TS entry to a single content script
|
|
import * as esbuild from 'esbuild';
|
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
|
|
const isWatch = process.argv.includes('--watch');
|
|
// Bundle lives under extension/dist/content/ so Chrome can load the
|
|
// extension directory without needing any files outside it.
|
|
const outdir = 'extension/dist/content';
|
|
|
|
if (!existsSync(outdir)) mkdirSync(outdir, { recursive: true });
|
|
|
|
const ctx = await esbuild.context({
|
|
entryPoints: ['extension/content/index.ts'],
|
|
bundle: true,
|
|
format: 'iife',
|
|
target: 'chrome109',
|
|
outfile: `${outdir}/index.js`,
|
|
sourcemap: 'linked',
|
|
logLevel: 'info',
|
|
banner: { js: '/* Beat Pocket content script */' },
|
|
});
|
|
|
|
if (isWatch) {
|
|
await ctx.watch();
|
|
console.log('esbuild watching…');
|
|
} else {
|
|
const r = await ctx.rebuild();
|
|
await ctx.dispose();
|
|
if (r.errors.length) process.exit(1);
|
|
console.log('build complete');
|
|
}
|