35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
// 桌面端构建:esbuild 打主进程 / preload(CJS),Vite 打渲染层到 dist/renderer
|
||
import { build as esbuild, context } from 'esbuild';
|
||
import { build as viteBuild } from 'vite';
|
||
import { copyFile, cp, mkdir, rm } from 'node:fs/promises';
|
||
|
||
const watch = process.argv.includes('--watch');
|
||
|
||
await rm('dist', { recursive: true, force: true });
|
||
await mkdir('dist', { recursive: true });
|
||
// 打包后首次运行要把 .env 模板复制到 userData;electron-builder 的 extraResources 会漏掉点开头的文件,所以进 asar
|
||
await copyFile('.env.example', 'dist/env.example');
|
||
await cp('resources/brand', 'dist/brand', { recursive: true });
|
||
|
||
const mainOptions = {
|
||
entryPoints: { main: 'electron/main.ts', preload: 'electron/preload.ts' },
|
||
bundle: true,
|
||
platform: 'node',
|
||
target: 'node22',
|
||
format: 'cjs',
|
||
outdir: 'dist',
|
||
outExtension: { '.js': '.cjs' },
|
||
external: ['electron'],
|
||
sourcemap: true,
|
||
logLevel: 'info',
|
||
};
|
||
|
||
if (watch) {
|
||
const ctx = await context(mainOptions);
|
||
await ctx.watch();
|
||
} else {
|
||
await esbuild(mainOptions);
|
||
}
|
||
|
||
await viteBuild({ configFile: 'vite.config.ts', build: watch ? { watch: {} } : undefined });
|