@@ -16,11 +16,13 @@ import { globalState } from './global-state';
16
16
import { tempPath } from './structor-config' ;
17
17
import { logInfo } from './log' ;
18
18
import { getWebpackConfig , IOptions } from './webpack-config' ;
19
+ import { pri } from '../node' ;
19
20
20
21
const smp = new SpeedMeasurePlugin ( ) ;
21
22
22
23
interface IExtraOptions {
23
24
pipeConfig ?: ( config ?: webpack . Configuration ) => Promise < webpack . Configuration > ;
25
+ pipeDevServerConfig ?: ( config ?: WebpackDevServer . Configuration ) => Promise < webpack . Configuration > ;
24
26
devServerPort : number ;
25
27
publicPath : string ;
26
28
jsOnly ?: boolean ;
@@ -74,8 +76,8 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
74
76
) ;
75
77
}
76
78
77
- const webpackDevServerConfig : WebpackDevServer . Configuration = {
78
- host : 'localhost' ,
79
+ let webpackDevServerConfig : WebpackDevServer . Configuration = {
80
+ host : pri . sourceConfig . devHost || 'localhost' ,
79
81
hot : opts . hot ,
80
82
hotOnly : opts . hot ,
81
83
publicPath : opts . publicPath ,
@@ -113,6 +115,10 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
113
115
port : opts . devServerPort ,
114
116
} as any ;
115
117
118
+ if ( opts . pipeDevServerConfig ) {
119
+ webpackDevServerConfig = await opts . pipeDevServerConfig ( webpackDevServerConfig ) ;
120
+ }
121
+
116
122
WebpackDevServer . addDevServerEntrypoints ( webpackConfig as any , webpackDevServerConfig ) ;
117
123
118
124
if ( yargs . argv . measureSpeed ) {
@@ -123,14 +129,16 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
123
129
124
130
const devServer = new WebpackDevServer ( compiler as any , webpackDevServerConfig ) ;
125
131
126
- devServer . listen ( opts . devServerPort , 'localhost' , ( ) => {
132
+ const host = pri . sourceConfig . devHost || webpackDevServerConfig . host || 'localhost' ;
133
+
134
+ devServer . listen ( opts . devServerPort , host , ( ) => {
127
135
let devUrl : string = null ;
128
136
const localSuggestUrl = urlJoin (
129
- `${ opts . https || globalState . sourceConfig . useHttps ? 'https' : 'http' } ://localhost :${ opts . devServerPort } ` ,
137
+ `${ opts . https || globalState . sourceConfig . useHttps ? 'https' : 'http' } ://${ host } :${ opts . devServerPort } ` ,
130
138
globalState . sourceConfig . baseHref ,
131
139
) ;
132
140
133
- if ( opts . devUrl === 'localhost' ) {
141
+ if ( opts . devUrl === host ) {
134
142
devUrl = localSuggestUrl ;
135
143
} else if ( opts . devUrl !== undefined ) {
136
144
( { devUrl } = opts ) ;
0 commit comments