@@ -2,6 +2,16 @@ import type { ForgeConfig } from "@electron-forge/shared-types";
22import path from "path" ;
33import 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+
515const config : ForgeConfig = {
616 outDir : "out-desktop" ,
717 packagerConfig : {
@@ -16,24 +26,20 @@ const config: ForgeConfig = {
1626 return false ;
1727 } else if ( path . match ( / d e s k t o p / ) ) {
1828 return false ;
29+ } else if ( path . match ( / n o d e _ m o d u l e s / ) ) {
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