feat: 编译exe问题调试
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user