@@ -2,13 +2,13 @@ import chalk from 'chalk';
22import { WebpackOptionsNormalized } from 'webpack' ;
33import Context , { ITaskConfig } from '../core/Context' ;
44import webpackStats from '../utils/webpackStats' ;
5+ import type WebpackDevServer from 'webpack-dev-server' ;
56import { IRunOptions } from '../types' ;
67import deepmerge = require( 'deepmerge' ) ;
7- import WebpackDevServer = require( 'webpack-dev-server' ) ;
88import prepareURLs = require( '../utils/prepareURLs' ) ;
99import log = require( '../utils/log' ) ;
1010
11- type DevServer = Record < string , any > ;
11+ type DevServerConfig = Record < string , any > ;
1212
1313export = async function ( context : Context , options ?: IRunOptions ) : Promise < void | ITaskConfig [ ] | WebpackDevServer > {
1414 const { eject } = options || { } ;
@@ -28,7 +28,7 @@ export = async function(context: Context, options?: IRunOptions): Promise<void |
2828 }
2929
3030 let serverUrl = '' ;
31- let devServerConfig : DevServer = {
31+ let devServerConfig : DevServerConfig = {
3232 port : commandArgs . port || 3333 ,
3333 host : commandArgs . host || '0.0.0.0' ,
3434 https : commandArgs . https || false ,
@@ -90,31 +90,20 @@ export = async function(context: Context, options?: IRunOptions): Promise<void |
9090 // context may hijack webpack resolve
9191 // eslint-disable-next-line @typescript-eslint/no-var-requires
9292 const DevServer = require ( 'webpack-dev-server' ) ;
93- const devServer = new DevServer ( compiler , devServerConfig ) ;
93+ const devServer : WebpackDevServer = new DevServer ( devServerConfig , compiler ) ;
9494
9595 await applyHook ( `before.${ command } .devServer` , {
9696 url : serverUrl ,
9797 urls,
9898 devServer,
9999 } ) ;
100100
101- devServer . listen (
102- devServerConfig . port ,
103- devServerConfig . host ,
104- async ( err : Error ) => {
105- if ( err ) {
106- log . info (
107- 'WEBPACK' ,
108- chalk . red ( '[ERR]: Failed to start webpack dev server' ) ,
109- ) ;
110- log . error ( 'WEBPACK' , err . stack || err . toString ( ) ) ;
111- }
112-
113- await applyHook ( `after.${ command } .devServer` , {
101+ devServer . startCallback (
102+ ( ) => {
103+ applyHook ( `after.${ command } .devServer` , {
114104 url : serverUrl ,
115105 urls,
116106 devServer,
117- err,
118107 } ) ;
119108 } ,
120109 ) ;
0 commit comments