Skip to content

Commit 3ea59f3

Browse files
committed
feat: plugin support
1 parent 93c191a commit 3ea59f3

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/Server.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ const DEFAULT_ALLOWED_PROTOCOLS = /^(file|.+-extension):/i;
311311
* @property {typeof useFn} use
312312
*/
313313

314+
const pluginName = "webpack-dev-server";
315+
314316
/**
315317
* @template {BasicApplication} [A=ExpressApplication]
316318
* @template {BasicServer} [S=HTTPServer]
@@ -330,7 +332,7 @@ class Server {
330332
/**
331333
* @type {ReturnType<Compiler["getInfrastructureLogger"]>}
332334
*/
333-
this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server");
335+
this.logger = this.compiler.getInfrastructureLogger(pluginName);
334336
this.options = options;
335337
/**
336338
* @type {FSWatcher[]}
@@ -3429,6 +3431,23 @@ class Server {
34293431
.then(() => callback(), callback)
34303432
.catch(callback);
34313433
}
3434+
3435+
/**
3436+
* @param {Compiler} compiler compiler
3437+
* @returns {void}
3438+
*/
3439+
apply(compiler) {
3440+
const pluginName = this.constructor.name;
3441+
this.compiler = compiler;
3442+
3443+
this.compiler.hooks.watchRun.tapPromise(pluginName, async () => {
3444+
await this.start();
3445+
});
3446+
3447+
this.compiler.hooks.watchClose.tap(pluginName, async () => {
3448+
await this.stop();
3449+
});
3450+
}
34323451
}
34333452

34343453
module.exports = Server;

0 commit comments

Comments
 (0)