@@ -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[] }
@@ -1587,6 +1590,9 @@ class Server {
15871590 * @returns {void }
15881591 */
15891592 setupProgressPlugin ( ) {
1593+ // In the case where there is no compiler and it’s not being used as a plugin.
1594+ if ( this . compiler === undefined ) return ;
1595+
15901596 const { ProgressPlugin } =
15911597 /** @type {MultiCompiler } */
15921598 ( this . compiler ) . compilers
@@ -1631,6 +1637,7 @@ class Server {
16311637 * @returns {Promise<void> }
16321638 */
16331639 async initialize ( ) {
1640+ if ( this . compiler === undefined ) return ;
16341641 this . setupHooks ( ) ;
16351642
16361643 await this . setupApp ( ) ;
@@ -1706,7 +1713,7 @@ class Server {
17061713 needForceShutdown = true ;
17071714
17081715 this . stopCallback ( ( ) => {
1709- if ( typeof this . compiler . close === "function" ) {
1716+ if ( typeof this . compiler ? .close === "function" ) {
17101717 this . compiler . close ( ( ) => {
17111718 // eslint-disable-next-line n/no-process-exit
17121719 process . exit ( ) ;
@@ -1781,11 +1788,14 @@ class Server {
17811788 * @returns {void }
17821789 */
17831790 setupHooks ( ) {
1791+ if ( this . compiler === undefined ) return ;
1792+
17841793 this . compiler . hooks . invalid . tap ( "webpack-dev-server" , ( ) => {
17851794 if ( this . webSocketServer ) {
17861795 this . sendMessage ( this . webSocketServer . clients , "invalid" ) ;
17871796 }
17881797 } ) ;
1798+
17891799 this . compiler . hooks . done . tap (
17901800 "webpack-dev-server" ,
17911801 /**
@@ -1840,6 +1850,7 @@ class Server {
18401850 * @returns {void }
18411851 */
18421852 setupMiddlewares ( ) {
1853+ if ( this . compiler === undefined ) return ;
18431854 /**
18441855 * @type {Array<Middleware> }
18451856 */
@@ -2331,6 +2342,7 @@ class Server {
23312342 // middleware for serving webpack bundle
23322343 /** @type {import("webpack-dev-middleware").API<Request, Response> } */
23332344 this . middleware = webpackDevMiddleware (
2345+ // @ts -expect-error
23342346 this . compiler ,
23352347 this . options . devMiddleware ,
23362348 ) ;
@@ -3437,8 +3449,8 @@ class Server {
34373449 * @returns {void }
34383450 */
34393451 apply ( compiler ) {
3440- const pluginName = this . constructor . name ;
34413452 this . compiler = compiler ;
3453+ this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
34423454
34433455 this . compiler . hooks . watchRun . tapPromise ( pluginName , async ( ) => {
34443456 await this . start ( ) ;
0 commit comments