Skip to content

Commit d6bba3b

Browse files
committed
feat: plugin support
1 parent d163488 commit d6bba3b

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[]}
@@ -3414,6 +3416,23 @@ class Server {
34143416
.then(() => callback(), callback)
34153417
.catch(callback);
34163418
}
3419+
3420+
/**
3421+
* @param {Compiler} compiler compiler
3422+
* @returns {void}
3423+
*/
3424+
apply(compiler) {
3425+
const pluginName = this.constructor.name;
3426+
this.compiler = compiler;
3427+
3428+
this.compiler.hooks.watchRun.tapPromise(pluginName, async () => {
3429+
await this.start();
3430+
});
3431+
3432+
this.compiler.hooks.watchClose.tap(pluginName, async () => {
3433+
await this.stop();
3434+
});
3435+
}
34173436
}
34183437

34193438
module.exports = Server;

0 commit comments

Comments
 (0)