MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

test/configCases/asset-modules/http-url/server/index.js:97–131  ·  view source on GitHub ↗

* @param {Compiler} compiler compiler

(compiler)

Source from the content-addressed store, hash-verified

95 * @param {Compiler} compiler compiler
96 */
97 apply(compiler) {
98 compiler.hooks.beforeRun.tapPromise(
99 "ServerPlugin",
100 async () => {
101 this.refs++;
102 if (!this.server) {
103 this.server = createServer();
104 await new Promise(
105 /**
106 * @param {(value: void) => void} resolve resolve
107 * @param {(reason?: Error) => void} _reject reject
108 */
109 (resolve, _reject) => {
110 /** @type {import("http").Server} */
111 (this.server).listen(
112 this.port,
113 () => {
114 resolve();
115 }
116 );
117 });
118 }
119 }
120 );
121
122 compiler.hooks.done.tapAsync("ServerPlugin", (stats, callback) => {
123 const s = this.server;
124 if (s && --this.refs === 0) {
125 this.server = undefined;
126 s.close(callback);
127 } else {
128 callback();
129 }
130 });
131 }
132}
133
134module.exports = ServerPlugin;

Callers

nothing calls this directly

Calls 4

createServerFunction · 0.85
resolveFunction · 0.85
callbackFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected