@@ -328,11 +328,14 @@ class Server {
328328 baseDataPath : "options" ,
329329 } ) ;
330330
331- this . compiler = compiler ;
332- /**
333- * @type {ReturnType<Compiler["getInfrastructureLogger"]> }
334- */
335- this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
331+ if ( compiler ) {
332+ this . compiler = compiler ;
333+
334+ /**
335+ * @type {ReturnType<Compiler["getInfrastructureLogger"]> }
336+ */
337+ this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
338+ }
336339 this . options = options ;
337340 /**
338341 * @type {FSWatcher[] }
@@ -1589,6 +1592,9 @@ class Server {
15891592 * @returns {void }
15901593 */
15911594 setupProgressPlugin ( ) {
1595+ // In the case where there is no compiler and it’s not being used as a plugin.
1596+ if ( this . compiler === undefined ) return ;
1597+
15921598 const { ProgressPlugin } =
15931599 /** @type {MultiCompiler } */
15941600 ( this . compiler ) . compilers
@@ -1633,6 +1639,7 @@ class Server {
16331639 * @returns {Promise<void> }
16341640 */
16351641 async initialize ( ) {
1642+ if ( this . compiler === undefined ) return ;
16361643 this . setupHooks ( ) ;
16371644
16381645 await this . setupApp ( ) ;
@@ -1708,7 +1715,7 @@ class Server {
17081715 needForceShutdown = true ;
17091716
17101717 this . stopCallback ( ( ) => {
1711- if ( typeof this . compiler . close === "function" ) {
1718+ if ( typeof this . compiler ? .close === "function" ) {
17121719 this . compiler . close ( ( ) => {
17131720 // eslint-disable-next-line n/no-process-exit
17141721 process . exit ( ) ;
@@ -1783,11 +1790,14 @@ class Server {
17831790 * @returns {void }
17841791 */
17851792 setupHooks ( ) {
1793+ if ( this . compiler === undefined ) return ;
1794+
17861795 this . compiler . hooks . invalid . tap ( "webpack-dev-server" , ( ) => {
17871796 if ( this . webSocketServer ) {
17881797 this . sendMessage ( this . webSocketServer . clients , "invalid" ) ;
17891798 }
17901799 } ) ;
1800+
17911801 this . compiler . hooks . done . tap (
17921802 "webpack-dev-server" ,
17931803 /**
@@ -1842,6 +1852,7 @@ class Server {
18421852 * @returns {void }
18431853 */
18441854 setupMiddlewares ( ) {
1855+ if ( this . compiler === undefined ) return ;
18451856 /**
18461857 * @type {Array<Middleware> }
18471858 */
@@ -2333,6 +2344,7 @@ class Server {
23332344 // middleware for serving webpack bundle
23342345 /** @type {import("webpack-dev-middleware").API<Request, Response> } */
23352346 this . middleware = webpackDevMiddleware (
2347+ // @ts -expect-error
23362348 this . compiler ,
23372349 this . options . devMiddleware ,
23382350 ) ;
@@ -3407,8 +3419,8 @@ class Server {
34073419 * @returns {void }
34083420 */
34093421 apply ( compiler ) {
3410- const pluginName = this . constructor . name ;
34113422 this . compiler = compiler ;
3423+ this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
34123424
34133425 this . compiler . hooks . watchRun . tapPromise ( pluginName , async ( ) => {
34143426 await this . start ( ) ;
0 commit comments