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
@@ -44,8 +45,11 @@ var optimist = require("optimist")
44
45
45
46
. boolean ( "compress" ) . describe ( "compress" , "enable gzip compression" )
46
47
48
+ . boolean ( "open" ) . describe ( "open" , "Open default browser" )
49
+
47
50
. describe ( "port" , "The port" ) . default ( "port" , 8080 )
48
51
52
+
49
53
. describe ( "host" , "The hostname/ip address the server will bind to" ) . default ( "host" , "localhost" ) ;
50
54
51
55
require ( "webpack/bin/config-optimist" ) ( optimist ) ;
@@ -137,6 +141,9 @@ if(argv["history-api-fallback"])
137
141
if ( argv [ "compress" ] )
138
142
options . compress = true ;
139
143
144
+ if ( argv [ "open" ] )
145
+ options . open = true ;
146
+
140
147
var protocol = options . https ? "https" : "http" ;
141
148
142
149
if ( options . inline ) {
@@ -156,16 +163,20 @@ if(options.inline) {
156
163
}
157
164
158
165
new Server ( webpack ( wpOpt ) , options ) . listen ( options . port , options . host , function ( err ) {
166
+ var uri = protocol + "://" + options . host + ":" + options . port + "/" ;
167
+
159
168
if ( err ) throw err ;
160
169
if ( options . inline )
161
- console . log ( protocol + "://" + options . host + ":" + options . port + "/" ) ;
170
+ console . log ( uri ) ;
162
171
else
163
- console . log ( protocol + "://" + options . host + ":" + options . port + "/ webpack-dev-server/") ;
172
+ console . log ( uri + "webpack-dev-server/" ) ;
164
173
console . log ( "webpack result is served from " + options . publicPath ) ;
165
174
if ( typeof options . contentBase === "object" )
166
175
console . log ( "requests are proxied to " + options . contentBase . target ) ;
167
176
else
168
177
console . log ( "content is served from " + options . contentBase ) ;
169
178
if ( options . historyApiFallback )
170
179
console . log ( "404s will fallback to %s" , options . historyApiFallback . index || "/index.html" ) ;
180
+ if ( options . open )
181
+ open ( uri ) ;
171
182
} ) ;
0 commit comments