Skip to content

Commit 0ee2dbb

Browse files
fix(plugin-webpack): ensure methods are bound to class instance
1 parent 9674ba0 commit 0ee2dbb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/plugin/webpack/src/WebpackPlugin.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ import { WebpackPluginConfig, WebpackPluginEntryPoint } from './Config';
1515

1616
const BASE_PORT = 3000;
1717

18-
export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
18+
export default class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
1919
name = 'webpack';
2020
private isProd = false;
2121
private baseDir!: string;
2222

23+
constructor(c: WebpackPluginConfig) {
24+
super(c);
25+
26+
this.startLogic = this.startLogic.bind(this);
27+
this.getHook = this.getHook.bind(this);
28+
}
29+
2330
private resolveConfig = (config: Configuration | string) => {
2431
if (typeof config === 'string') return require(config) as Configuration;
2532
return config;
@@ -41,7 +48,7 @@ export class WebpackPlugin extends PluginBase<WebpackPluginConfig> {
4148
return null;
4249
}
4350

44-
async getMainConfig() {
51+
getMainConfig = async () => {
4552
const mainConfig = this.resolveConfig(this.config.mainConfig);
4653

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

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

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

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

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

149-
async spinDev() {
156+
async startLogic(): Promise<false> {
150157
await this.compileMain();
151158
await this.launchDevServers();
152159
return false;

0 commit comments

Comments
 (0)