Skip to content

Commit

Permalink
fix(plugin-webpack): lazily load config generator so isProd is set co…
Browse files Browse the repository at this point in the history
…rrectly (#1480)
  • Loading branch information
malept authored Feb 5, 2020
1 parent b1f3b72 commit 9f6a445
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions packages/plugin/webpack/src/WebpackConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import webpack, { Configuration } from 'webpack';
Expand All @@ -7,6 +8,8 @@ import { WebpackPluginConfig, WebpackPluginEntryPoint, WebpackPreloadEntryPoint

type EntryType = string | string[] | Record<string, string | string[]>;

const d = debug('electron-forge:plugin:webpack:webpackconfig');

export default class WebpackConfigGenerator {
private isProd: boolean;

Expand All @@ -29,6 +32,8 @@ export default class WebpackConfigGenerator {
this.webpackDir = path.resolve(projectDir, '.webpack');
this.isProd = isProd;
this.port = port;

d('Config mode:', this.mode);
}

resolveConfig(config: Configuration | string) {
Expand Down
23 changes: 16 additions & 7 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {

private baseDir!: string;

private configGenerator!: WebpackConfigGenerator;
private _configGenerator!: WebpackConfigGenerator;

private watchers: webpack.Compiler.Watching[] = [];

Expand Down Expand Up @@ -128,13 +128,22 @@ export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
setDirectories = (dir: string) => {
this.projectDir = dir;
this.baseDir = path.resolve(dir, '.webpack');
}

this.configGenerator = new WebpackConfigGenerator(
this.config,
this.projectDir,
this.isProd,
this.port,
);
get configGenerator() {
// eslint-disable-next-line no-underscore-dangle
if (!this._configGenerator) {
// eslint-disable-next-line no-underscore-dangle
this._configGenerator = new WebpackConfigGenerator(
this.config,
this.projectDir,
this.isProd,
this.port,
);
}

// eslint-disable-next-line no-underscore-dangle
return this._configGenerator;
}

private loggedOutputUrl = false;
Expand Down

0 comments on commit 9f6a445

Please sign in to comment.