Skip to content

Commit e823546

Browse files
committed
feat: plugin support
1 parent 6cd1752 commit e823546

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[]}
@@ -3399,6 +3401,23 @@ class Server {
33993401
.then(() => callback(), callback)
34003402
.catch(callback);
34013403
}
3404+
3405+
/**
3406+
* @param {Compiler} compiler compiler
3407+
* @returns {void}
3408+
*/
3409+
apply(compiler) {
3410+
const pluginName = this.constructor.name;
3411+
this.compiler = compiler;
3412+
3413+
this.compiler.hooks.watchRun.tapPromise(pluginName, async () => {
3414+
await this.start();
3415+
});
3416+
3417+
this.compiler.hooks.watchClose.tap(pluginName, async () => {
3418+
await this.stop();
3419+
});
3420+
}
34023421
}
34033422

34043423
module.exports = Server;

0 commit comments

Comments
 (0)