Skip to content
Permalink
Browse files

fix(plugin-webpack): ensure methods are bound to class instance

  • Loading branch information
MarshallOfSound committed May 4, 2018
1 parent 9674ba0 commit 0ee2dbb55fc61cbc36baf23a8f87d2eeac3be716
Showing with 14 additions and 7 deletions.
  1. +14 −7 packages/plugin/webpack/src/WebpackPlugin.ts
@@ -15,11 +15,18 @@ import { WebpackPluginConfig, WebpackPluginEntryPoint } from './Config';

const BASE_PORT = 3000;

export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
name = 'webpack';
private isProd = false;
private baseDir!: string;

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

this.startLogic = this.startLogic.bind(this);
this.getHook = this.getHook.bind(this);
}

private resolveConfig = (config: Configuration | string) => {
if (typeof config === 'string') return require(config) as Configuration;
return config;
@@ -41,7 +48,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
return null;
}

async getMainConfig() {
getMainConfig = async () => {
const mainConfig = this.resolveConfig(this.config.mainConfig);

if (!mainConfig.entry) {
@@ -75,7 +82,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
}, mainConfig || {});
}

async getRendererConfig(entryPoint: WebpackPluginEntryPoint) {
getRendererConfig = async (entryPoint: WebpackPluginEntryPoint) => {
const rendererConfig = this.resolveConfig(this.config.renderer.config);
const prefixedEntries = this.config.renderer.prefixedEntries || [];
return merge.smart({
@@ -101,7 +108,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
}, rendererConfig);
}

async compileMain() {
compileMain = async () => {
await asyncOra('Compiling Main Process Code', async () => {
await new Promise(async (resolve, reject) => {
webpack(await this.getMainConfig()).run((err, stats) => {
@@ -112,7 +119,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
});
}

async compileRenderers() {
compileRenderers = async () => {
for (const entryPoint of this.config.renderer.entryPoints) {
await asyncOra(`Compiling Renderer Template: ${entryPoint.name}`, async () => {
await new Promise(async (resolve, reject) => {
@@ -125,7 +132,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
}
}

async launchDevServers() {
launchDevServers = async () => {
await asyncOra('Launch Dev Servers', async () => {
let index = 0;
for (const entryPoint of this.config.renderer.entryPoints) {
@@ -146,7 +153,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
});
}

async spinDev() {
async startLogic(): Promise<false> {
await this.compileMain();
await this.launchDevServers();
return false;

0 comments on commit 0ee2dbb

Please sign in to comment.
You can’t perform that action at this time.