- Replace symlinks in .next/standalone with real copies for electron-builder - Exclude electron/, dist-electron/, scripts/, release/ from tsconfig - Use arm64 target instead of universal to avoid native module merge issues Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
import { build } from 'esbuild';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// Replace symlinks in standalone with real copies so electron-builder can package them
|
|
function resolveStandaloneSymlinks() {
|
|
const standaloneModules = '.next/standalone/.next/node_modules';
|
|
if (!fs.existsSync(standaloneModules)) return;
|
|
|
|
const entries = fs.readdirSync(standaloneModules);
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(standaloneModules, entry);
|
|
const stat = fs.lstatSync(fullPath);
|
|
if (stat.isSymbolicLink()) {
|
|
const target = fs.readlinkSync(fullPath);
|
|
const resolved = path.resolve(standaloneModules, target);
|
|
if (fs.existsSync(resolved)) {
|
|
fs.rmSync(fullPath);
|
|
fs.cpSync(resolved, fullPath, { recursive: true });
|
|
console.log(`Resolved symlink: ${entry} -> ${target}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function buildElectron() {
|
|
const shared = {
|
|
bundle: true,
|
|
platform: 'node',
|
|
target: 'node18',
|
|
external: ['electron'],
|
|
sourcemap: true,
|
|
minify: false,
|
|
};
|
|
|
|
await build({
|
|
...shared,
|
|
entryPoints: ['electron/main.ts'],
|
|
outfile: 'dist-electron/main.js',
|
|
});
|
|
|
|
await build({
|
|
...shared,
|
|
entryPoints: ['electron/preload.ts'],
|
|
outfile: 'dist-electron/preload.js',
|
|
});
|
|
|
|
console.log('Electron build complete');
|
|
|
|
// Fix standalone symlinks after next build
|
|
resolveStandaloneSymlinks();
|
|
}
|
|
|
|
buildElectron().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|