@@ -15,6 +15,8 @@ if (!process.env.WEBPACK_SERVE) {
1515 process . env . WEBPACK_SERVE = true ;
1616}
1717
18+ const pluginName = "webpack-dev-server" ;
19+
1820class Server {
1921 constructor ( options = { } , compiler ) {
2022 // TODO: remove this after plugin support is published
@@ -41,11 +43,6 @@ class Server {
4143 }
4244 }
4345
44- apply ( compiler ) {
45- this . compiler = compiler ;
46- this . start ( ) ;
47- }
48-
4946 static get DEFAULT_STATS ( ) {
5047 return {
5148 all : false ,
@@ -134,6 +131,20 @@ class Server {
134131 return path . resolve ( dir , "node_modules/.cache/webpack-dev-server" ) ;
135132 }
136133
134+ apply ( compiler ) {
135+ this . compiler = compiler ;
136+
137+ let started = false ;
138+
139+ compiler . hooks . watchRun . tapPromise ( pluginName , async ( ) => {
140+ if ( ! started ) {
141+ await this . start ( ) ;
142+
143+ started = true ;
144+ }
145+ } ) ;
146+ }
147+
137148 addAdditionalEntries ( compiler ) {
138149 const additionalEntries = [ ] ;
139150
@@ -403,7 +414,7 @@ class Server {
403414 const { options } = this ;
404415
405416 if ( ! this . logger ) {
406- this . logger = this . compiler . getInfrastructureLogger ( "webpack-dev-server" ) ;
417+ this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
407418 }
408419
409420 const compilerOptions = this . getCompilerOptions ( ) ;
@@ -696,7 +707,7 @@ class Server {
696707 if ( typeof options . ipc === "boolean" ) {
697708 const isWindows = process . platform === "win32" ;
698709 const pipePrefix = isWindows ? "\\\\.\\pipe\\" : os . tmpdir ( ) ;
699- const pipeName = "webpack-dev-server .sock" ;
710+ const pipeName = ` ${ pluginName } .sock` ;
700711
701712 options . ipc = path . join ( pipePrefix , pipeName ) ;
702713 }
@@ -1158,12 +1169,12 @@ class Server {
11581169 }
11591170
11601171 setupHooks ( ) {
1161- this . compiler . hooks . invalid . tap ( "webpack-dev-server" , ( ) => {
1172+ this . compiler . hooks . invalid . tap ( pluginName , ( ) => {
11621173 if ( this . webSocketServer ) {
11631174 this . sendMessage ( this . webSocketServer . clients , "invalid" ) ;
11641175 }
11651176 } ) ;
1166- this . compiler . hooks . done . tap ( "webpack-dev-server" , ( stats ) => {
1177+ this . compiler . hooks . done . tap ( pluginName , ( stats ) => {
11671178 if ( this . webSocketServer ) {
11681179 this . sendStats ( this . webSocketServer . clients , this . getStats ( stats ) ) ;
11691180 }
@@ -2146,7 +2157,7 @@ class Server {
21462157 }
21472158 }
21482159
2149- startCallback ( callback ) {
2160+ startCallback ( callback = ( ) => { } ) {
21502161 this . start ( ) . then ( ( ) => callback ( null ) , callback ) ;
21512162 }
21522163
@@ -2218,7 +2229,7 @@ class Server {
22182229 "DEP_WEBPACK_DEV_SERVER_LISTEN"
22192230 ) ( ) ;
22202231
2221- this . logger = this . compiler . getInfrastructureLogger ( "webpack-dev-server" ) ;
2232+ this . logger = this . compiler . getInfrastructureLogger ( pluginName ) ;
22222233
22232234 if ( typeof port === "function" ) {
22242235 fn = port ;
0 commit comments