Skip to content

Commit 3f8fe6e

Browse files
committed
Update electron forge after completion logic
1 parent ec2480d commit 3f8fe6e

File tree

3 files changed

+4158
-4797
lines changed

3 files changed

+4158
-4797
lines changed

desktop/main.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { app, BrowserWindow, dialog, ipcMain } from "electron";
22
import serve from "electron-serve";
33
import { join } from "path";
4-
54
import { fileURLToPath } from "url";
65
import path from "path";
76
import { nativeTheme } from "electron/main";

forge.config.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import type { ForgeConfig } from "@electron-forge/shared-types";
22
import path from "path";
33
import fs from "fs-extra";
44

5+
function removeNextjsModules(exceptionList: string[], extractPath: string) {
6+
const nodeModulesPath = path.join(extractPath, "resources/app/node_modules");
7+
8+
fs.readdirSync(nodeModulesPath).forEach((module) => {
9+
if (!exceptionList.includes(module)) {
10+
fs.removeSync(path.join(nodeModulesPath, module));
11+
}
12+
});
13+
}
14+
515
const config: ForgeConfig = {
616
outDir: "out-desktop",
717
packagerConfig: {
@@ -16,24 +26,20 @@ const config: ForgeConfig = {
1626
return false;
1727
} else if (path.match(/desktop/)) {
1828
return false;
29+
} else if (path.match(/node_modules/)) {
30+
return false;
1931
}
2032
return true;
2133
},
22-
extraResource: "node_modules/electron-serve",
2334
afterComplete: [
2435
(extractPath, electronVersion, platform, arch, done) => {
25-
// move node_modules/electron-serve to the app directory
26-
const from = path.join(extractPath, "node_modules/electron-serve");
27-
const to = path.join(
28-
extractPath,
29-
"resources/app/node_modules/electron-serve",
30-
);
31-
if (fs.existsSync(from)) {
32-
fs.moveSync(
33-
path.join(extractPath, "resources/electron-serve"),
34-
path.join(extractPath, "resources/app/node_modules/electron-serve"),
35-
);
36-
}
36+
// We need electron-serve to exist inside the electron build's node_modules.
37+
// All other modules from nextjs are not needed and can be removed.
38+
39+
const electronModules = ["electron-serve"];
40+
41+
removeNextjsModules(electronModules, extractPath);
42+
3743
done();
3844
},
3945
],

0 commit comments

Comments
 (0)