@@ -15,6 +15,7 @@ import * as path from 'node:path';
1515import * as url from 'node:url' ;
1616import * as util from 'node:util' ;
1717import ipaddr from 'ipaddr.js' ;
18+ import { getPort } from './getPort' ;
1819import { WebsocketServer } from './servers/WebsocketServer' ;
1920import type {
2021 AddressInfo ,
@@ -330,8 +331,9 @@ class Server<
330331 return port ;
331332 }
332333
333- const { default : pRetry } = await import ( 'p-retry' ) ;
334- const { getPort } = await import ( './getPort' ) ;
334+ const { default : pRetry } = await import (
335+ /* webpackChunkName: "p-retry" */ 'p-retry'
336+ ) ;
335337 const basePort =
336338 typeof process . env . RSPACK_DEV_SERVER_BASE_PORT !== 'undefined'
337339 ? Number . parseInt ( process . env . RSPACK_DEV_SERVER_BASE_PORT , 10 )
@@ -1457,7 +1459,7 @@ class Server<
14571459
14581460 this . setupWatchFiles ( ) ;
14591461 this . setupWatchStaticFiles ( ) ;
1460- this . setupMiddlewares ( ) ;
1462+ await this . setupMiddlewares ( ) ;
14611463
14621464 if ( this . options . setupExitSignals ) {
14631465 const signals = [ 'SIGINT' , 'SIGTERM' ] ;
@@ -1577,7 +1579,7 @@ class Server<
15771579 }
15781580 }
15791581
1580- setupMiddlewares ( ) : void {
1582+ async setupMiddlewares ( ) : Promise < void > {
15811583 let middlewares : Middleware [ ] = [ ] ;
15821584
15831585 // Register setup host header check for security
@@ -1644,7 +1646,9 @@ class Server<
16441646
16451647 // compress is placed last and uses unshift so that it will be the first middleware used
16461648 if ( this . options . compress ) {
1647- const compression = require ( 'compression' ) ;
1649+ const { default : compression } = await import (
1650+ /* webpackChunkName: "compression" */ 'compression'
1651+ ) ;
16481652 middlewares . push ( { name : 'compression' , middleware : compression ( ) } ) ;
16491653 }
16501654
0 commit comments