feat: 编译exe问题调试

This commit is contained in:
duanshuwen
2026-03-19 08:45:07 +08:00
parent 67850c63f7
commit c4a0e4f9a4
11 changed files with 660 additions and 115 deletions

View File

@@ -8,6 +8,7 @@ import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { FuseV1Options, FuseVersion } from '@electron/fuses';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as esbuild from 'esbuild';
const config: ForgeConfig = {
packagerConfig: {
@@ -62,7 +63,33 @@ const config: ForgeConfig = {
const src = path.join(__dirname, 'src/main/scripts');
const dest = path.join(buildPath, 'resources', 'scripts');
await fs.ensureDir(dest);
await fs.copy(src, dest);
// Bundle mjs scripts using esbuild
const files = await fs.readdir(src);
for (const file of files) {
if (file.endsWith('.mjs')) {
await esbuild.build({
entryPoints: [path.join(src, file)],
outfile: path.join(dest, file),
bundle: true,
platform: 'node',
target: 'node16', // Adjust based on Electron version
external: ['electron', 'chromium-bidi/lib/cjs/bidiMapper/BidiMapper', 'chromium-bidi/lib/cjs/cdp/CdpConnection'], // Exclude electron if imported
format: 'esm',
});
} else {
// Copy other files (e.g., .md, .png) directly
await fs.copy(path.join(src, file), path.join(dest, file));
}
}
// Force bytenode into the packaged node_modules since Forge Vite plugin ignores it
const bytenodeSrc = path.join(__dirname, 'node_modules', 'bytenode');
const bytenodeDest = path.join(buildPath, 'node_modules', 'bytenode');
if (await fs.pathExists(bytenodeSrc)) {
await fs.ensureDir(path.join(buildPath, 'node_modules'));
await fs.copy(bytenodeSrc, bytenodeDest);
}
},
async prePackage() {