Files
DndGamePlayer/scripts/build.mjs
T
     Фонтош Иван Сергеевич 5e7dc5ea19 fix(icons): паритет иконки окна с pack-иконкой и sync lockfile
- Копировать build/icon.png в dist/renderer/app-pack-icon.png после Vite
- Приоритет pack PNG для BrowserWindow; на win32/linux без SVG в nativeImage
- macOS: app.dock.setIcon из того же набора PNG
- package-lock.json в соответствии с package.json

Made-with: Cursor
2026-04-19 15:00:33 +08:00

58 lines
1.5 KiB
JavaScript

import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { build } from 'esbuild';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const root = path.resolve(__dirname, '..');
function runViteBuild() {
execFileSync('npx vite build', {
cwd: root,
stdio: 'inherit',
shell: true,
});
}
async function buildNodeTargets() {
await build({
entryPoints: [path.join(root, 'app/main/index.ts')],
outfile: path.join(root, 'dist/main/index.cjs'),
platform: 'node',
target: 'node22',
format: 'cjs',
bundle: true,
sourcemap: true,
external: ['electron'],
});
await build({
entryPoints: [path.join(root, 'app/preload/index.ts')],
outfile: path.join(root, 'dist/preload/index.cjs'),
platform: 'node',
target: 'node22',
format: 'cjs',
bundle: true,
sourcemap: true,
external: ['electron'],
});
}
await buildNodeTargets();
execFileSync('node', [path.join(root, 'scripts', 'gen-window-icon.mjs')], {
cwd: root,
stdio: 'inherit',
});
runViteBuild();
// Тот же PNG, что electron-builder кладёт в .exe/.app — в рантайме для окна/дока (паритет с Windows).
const packIcon = path.join(root, 'build', 'icon.png');
const distPackIcon = path.join(root, 'dist', 'renderer', 'app-pack-icon.png');
if (fs.existsSync(packIcon)) {
fs.copyFileSync(packIcon, distPackIcon);
console.log('copied pack icon to', distPackIcon);
}