In Electron Forge, changing the default port typically involves modifying the project's configuration files. Electron Forge is a popular tool for developing and building Electron applications. By default, Electron Forge may use a standard port for the development server, such as 3000 or 8080. However, in certain scenarios—particularly when a port conflict occurs—changing the port may be necessary.
Here is one method to change the default port of Electron Forge by modifying the webpack configuration (assuming you are using the webpack plugin):
-
Open the webpack configuration file: In an Electron Forge project, there are typically files named
webpack.main.config.jsandwebpack.renderer.config.jsthat configure webpack behavior. -
Modify the
devServeroption: In thewebpack.renderer.config.jsfile, locate thedevServersection, which is specifically used to configure the development server options. For example:javascriptconst config = { // Other configurations... devServer: { port: 3000, // Default port // Other server options... }, // Other configurations... }; -
Change the port number: Update the value of
portto your desired port number. For instance, if you want to set the port to4000, modify it as follows:javascriptdevServer: { port: 4000, } -
Save and restart the development server: Save the changes to the configuration file and restart the Electron Forge development server. This can be done by stopping the currently running server and then re-executing
npm startoryarn start. -
Verify the changes: After launching the application, confirm it is successfully running on the new port. Access it via
http://localhost:4000(or any port you configured) in a browser.
This process involves basic configuration adjustments. Always back up your configuration files before making any changes to facilitate restoring to the original settings if needed. If your configuration does not include webpack, consult the Electron Forge documentation or other relevant configuration files to identify the correct modification approach.