Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 4 packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ export interface WebpackPluginConfig {
* Electron Forge webpack configuration for your renderer process
*/
renderer: WebpackPluginRendererConfig;
/**
* The TCP port for the dev servers. Defaults to 3000.
*/
port?: number;
}
19 changes: 15 additions & 4 deletions 19 packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import once from './util/once';
import { WebpackPluginConfig, WebpackPluginEntryPoint, WebpackPreloadEntryPoint } from './Config';

const d = debug('electron-forge:plugin:webpack');
const BASE_PORT = 3000;
const DEFAULT_PORT = 3000;

export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
name = 'webpack';
Expand All @@ -30,10 +30,21 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
private watchers: webpack.Compiler.Watching[] = [];
private servers: http.Server[] = [];
private loggers: Logger[] = [];
private port = DEFAULT_PORT;

constructor(c: WebpackPluginConfig) {
super(c);

if (c.port) {
malept marked this conversation as resolved.
Show resolved Hide resolved
if (c.port < 1024) {
throw new Error(`Cannot specify port (${c.port}) below 1024, as they are privileged`);
} else if (c.port > 65535) {
throw new Error(`Port specified (${c.port}) is not a valid TCP port.`);
} else {
this.port = c.port;
}
}

this.startLogic = this.startLogic.bind(this);
this.getHook = this.getHook.bind(this);
}
Expand Down Expand Up @@ -153,12 +164,12 @@ Your packaged app may be larger than expected if you dont ignore everything othe
defines[`${entryPoint.name.toUpperCase().replace(/ /g, '_')}_WEBPACK_ENTRY`] =
this.isProd
? `\`file://\$\{require('path').resolve(__dirname, '../renderer', '${upOneMore ? '..' : '.'}', '${entryPoint.name}', 'index.html')\}\``
: `'http://localhost:${BASE_PORT}/${entryPoint.name}'`;
: `'http://localhost:${this.port}/${entryPoint.name}'`;
} else {
defines[`${entryPoint.name.toUpperCase().replace(/ /g, '_')}_WEBPACK_ENTRY`] =
this.isProd
? `\`file://\$\{require('path').resolve(__dirname, '../renderer', '${upOneMore ? '..' : '.'}', '${entryPoint.name}', 'index.js')\}\``
: `'http://localhost:${BASE_PORT}/${entryPoint.name}/index.js'`;
: `'http://localhost:${this.port}/${entryPoint.name}/index.js'`;
}

const preloadDefineKey = `${entryPoint.name.toUpperCase().replace(/ /g, '_')}_PRELOAD_WEBPACK_ENTRY`;
Expand Down Expand Up @@ -340,7 +351,7 @@ Your packaged app may be larger than expected if you dont ignore everything othe
const app = express();
app.use(server);
app.use(webpackHotMiddleware(compiler));
this.servers.push(app.listen(BASE_PORT));
this.servers.push(app.listen(this.port));
});

await asyncOra('Compiling Preload Scripts', async () => {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.