2
2
3
3
var path = require ( "path" ) ;
4
4
var url = require ( "url" ) ;
5
+ var open = require ( "open" ) ;
5
6
var fs = require ( "fs" ) ;
6
7
7
8
// Local version replaces global one
@@ -46,8 +47,11 @@ var optimist = require("optimist")
46
47
47
48
. boolean ( "compress" ) . describe ( "compress" , "enable gzip compression" )
48
49
50
+ . boolean ( "open" ) . describe ( "open" , "Open default browser" )
51
+
49
52
. describe ( "port" , "The port" ) . default ( "port" , 8080 )
50
53
54
+
51
55
. describe ( "host" , "The hostname/ip address the server will bind to" ) . default ( "host" , "localhost" ) ;
52
56
53
57
require ( "webpack/bin/config-optimist" ) ( optimist ) ;
@@ -147,6 +151,9 @@ if(argv["history-api-fallback"])
147
151
if ( argv [ "compress" ] )
148
152
options . compress = true ;
149
153
154
+ if ( argv [ "open" ] )
155
+ options . open = true ;
156
+
150
157
var protocol = options . https ? "https" : "http" ;
151
158
152
159
if ( options . inline ) {
@@ -166,16 +173,19 @@ if(options.inline) {
166
173
}
167
174
168
175
new Server ( webpack ( wpOpt ) , options ) . listen ( options . port , options . host , function ( err ) {
176
+ var uri = protocol + "://" + options . host + ":" + options . port + "/" ;
177
+ if ( ! options . inline )
178
+ uri += "webpack-dev-server/" ;
179
+
169
180
if ( err ) throw err ;
170
- if ( options . inline )
171
- console . log ( protocol + "://" + options . host + ":" + options . port + "/" ) ;
172
- else
173
- console . log ( protocol + "://" + options . host + ":" + options . port + "/webpack-dev-server/" ) ;
181
+ console . log ( uri ) ;
174
182
console . log ( "webpack result is served from " + options . publicPath ) ;
175
183
if ( typeof options . contentBase === "object" )
176
184
console . log ( "requests are proxied to " + options . contentBase . target ) ;
177
185
else
178
186
console . log ( "content is served from " + options . contentBase ) ;
179
187
if ( options . historyApiFallback )
180
188
console . log ( "404s will fallback to %s" , options . historyApiFallback . index || "/index.html" ) ;
189
+ if ( options . open )
190
+ open ( uri ) ;
181
191
} ) ;
0 commit comments