2026-04-25 06:12:17 +00:00
|
|
|
import esbuild from 'esbuild';
|
|
|
|
|
import { builtinModules } from 'module';
|
|
|
|
|
|
|
|
|
|
const production = process.argv[2] === 'production';
|
|
|
|
|
const watch = process.argv[2] === 'watch';
|
|
|
|
|
|
2026-05-09 02:48:36 +00:00
|
|
|
const external = ['obsidian', 'electron', ...builtinModules, ...builtinModules.map((m) => `node:${m}`)];
|
2026-04-25 06:12:17 +00:00
|
|
|
|
|
|
|
|
const context = await esbuild.context({
|
|
|
|
|
entryPoints: ['main.ts'],
|
|
|
|
|
bundle: true,
|
|
|
|
|
platform: 'node',
|
|
|
|
|
format: 'cjs',
|
2026-04-27 11:47:41 +00:00
|
|
|
target: 'es2022',
|
2026-04-25 06:12:17 +00:00
|
|
|
external,
|
2026-04-27 11:48:26 +00:00
|
|
|
sourcemap: production ? 'linked' : 'inline',
|
2026-04-25 06:12:17 +00:00
|
|
|
treeShaking: true,
|
|
|
|
|
minify: production,
|
|
|
|
|
outfile: 'main.js',
|
|
|
|
|
banner: {
|
|
|
|
|
js: "'use strict';",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (watch) {
|
|
|
|
|
await context.watch();
|
|
|
|
|
console.log('Watching for changes...');
|
|
|
|
|
} else {
|
|
|
|
|
await context.rebuild();
|
|
|
|
|
await context.dispose();
|
|
|
|
|
}
|