@@ -83,7 +83,7 @@ function clearConsole() {
83
83
isFirstClear = false ;
84
84
}
85
85
86
- function setupCompiler ( port , protocol ) {
86
+ function setupCompiler ( host , port , protocol ) {
87
87
// "Compiler" is a low-level interface to Webpack.
88
88
// It lets us listen to some events and provide our own custom messages.
89
89
compiler = webpack ( config , handleCompile ) ;
@@ -108,7 +108,7 @@ function setupCompiler(port, protocol) {
108
108
console . log ( ) ;
109
109
console . log ( 'The app is running at:' ) ;
110
110
console . log ( ) ;
111
- console . log ( ' ' + chalk . cyan ( protocol + '://localhost :' + port + '/' ) ) ;
111
+ console . log ( ' ' + chalk . cyan ( protocol + '://' + host + ' :' + port + '/' ) ) ;
112
112
console . log ( ) ;
113
113
console . log ( 'Note that the development build is not optimized.' ) ;
114
114
console . log ( 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.' ) ;
@@ -159,14 +159,14 @@ function setupCompiler(port, protocol) {
159
159
} ) ;
160
160
}
161
161
162
- function openBrowser ( port , protocol ) {
162
+ function openBrowser ( host , port , protocol ) {
163
163
if ( process . platform === 'darwin' ) {
164
164
try {
165
165
// Try our best to reuse existing tab
166
166
// on OS X Google Chrome with AppleScript
167
167
execSync ( 'ps cax | grep "Google Chrome"' ) ;
168
168
execSync (
169
- 'osascript chrome.applescript ' + protocol + '://localhost :' + port + '/' ,
169
+ 'osascript chrome.applescript ' + protocol + '://' + host + ' :' + port + '/' ,
170
170
{ cwd : path . join ( __dirname , 'utils' ) , stdio : 'ignore' }
171
171
) ;
172
172
return ;
@@ -177,7 +177,7 @@ function openBrowser(port, protocol) {
177
177
// Fallback to opn
178
178
// (It will always open new tab)
179
179
try {
180
- opn ( protocol + '://localhost :' + port + '/' ) ;
180
+ opn ( protocol + '://' + host + ' :' + port + '/' ) ;
181
181
} catch ( err ) {
182
182
// Ignore errors.
183
183
}
@@ -260,7 +260,7 @@ function addMiddleware(devServer) {
260
260
devServer . use ( devServer . middleware ) ;
261
261
}
262
262
263
- function runDevServer ( port , protocol ) {
263
+ function runDevServer ( host , port , protocol ) {
264
264
var devServer = new WebpackDevServer ( compiler , {
265
265
// Silence WebpackDevServer's own logs since they're generally not useful.
266
266
// It will still show compile warnings and errors with this setting.
@@ -298,7 +298,8 @@ function runDevServer(port, protocol) {
298
298
ignored : / n o d e _ m o d u l e s /
299
299
} ,
300
300
// Enable HTTPS if the HTTPS environment variable is set to 'true'
301
- https : protocol === "https" ? true : false
301
+ https : protocol === "https" ? true : false ,
302
+ host : host
302
303
} ) ;
303
304
304
305
// Our custom middleware proxies requests to /index.html or a remote API.
@@ -313,15 +314,16 @@ function runDevServer(port, protocol) {
313
314
clearConsole ( ) ;
314
315
console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
315
316
console . log ( ) ;
316
- openBrowser ( port , protocol ) ;
317
+ openBrowser ( host , port , protocol ) ;
317
318
} ) ;
318
319
}
319
320
320
321
function run ( port ) {
321
322
var protocol = process . env . HTTPS === 'true' ? "https" : "http" ;
323
+ var host = process . env . HOST || 'localhost' ;
322
324
checkRequiredFiles ( ) ;
323
- setupCompiler ( port , protocol ) ;
324
- runDevServer ( port , protocol ) ;
325
+ setupCompiler ( host , port , protocol ) ;
326
+ runDevServer ( host , port , protocol ) ;
325
327
}
326
328
327
329
// We attempt to use the default port but if it is busy, we offer the user to
0 commit comments