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
@@ -17,44 +18,50 @@ var webpack = require("webpack");
17
18
18
19
var optimist = require ( "optimist" )
19
20
20
- . usage ( "webpack-dev-server " + require ( "../package.json" ) . version + "\n" +
21
- "Usage: http://webpack.github.io/docs/webpack-dev-server.html" )
21
+ . usage ( "webpack-dev-server " + require ( "../package.json" ) . version + "\n" +
22
+ "Usage: http://webpack.github.io/docs/webpack-dev-server.html" )
22
23
23
- . boolean ( "lazy" ) . describe ( "lazy" )
24
+ . boolean ( "lazy" ) . describe ( "lazy" )
24
25
25
- . boolean ( "info " ) . describe ( "info" ) . default ( "info" , true )
26
+ . boolean ( "stdin " ) . describe ( "stdin" , "close when stdin ends" )
26
27
27
- . boolean ( "quiet " ) . describe ( "quiet" )
28
+ . boolean ( "info " ) . describe ( "info" ) . default ( "info" , true )
28
29
29
- . boolean ( "inline " ) . describe ( "inline" , "Inline the webpack-dev-server logic into the bundle. ")
30
+ . boolean ( "quiet " ) . describe ( "quiet " )
30
31
31
- . boolean ( "https " ) . describe ( "https " )
32
+ . boolean ( "inline " ) . describe ( "inline" , "Inline the webpack-dev-server logic into the bundle. ")
32
33
33
- . string ( "key ") . describe ( "key" , "Path to a SSL key. ")
34
+ . boolean ( "https ") . describe ( "https " )
34
35
35
- . string ( "cert " ) . describe ( "cert " , "Path to a SSL certificate ." )
36
+ . string ( "key " ) . describe ( "key " , "Path to a SSL key ." )
36
37
37
- . string ( "cacert " ) . describe ( "cacert " , "Path to a SSL CA certificate." )
38
+ . string ( "cert " ) . describe ( "cert " , "Path to a SSL certificate." )
38
39
39
- . string ( "content-base " ) . describe ( "content-base " , "A directory or URL to serve HTML content from ." )
40
+ . string ( "cacert " ) . describe ( "cacert " , "Path to a SSL CA certificate ." )
40
41
41
- . string ( "content-base-target " ) . describe ( "content-base-target " , "Proxy requests to this target ." )
42
+ . string ( "content-base" ) . describe ( "content-base" , "A directory or URL to serve HTML content from ." )
42
43
43
- . boolean ( "history-api-fallback ") . describe ( "history-api-fallback " , "Fallback to /index.html for Single Page Applications ." )
44
+ . string ( "content-base-target ") . describe ( "content-base-target " , "Proxy requests to this target ." )
44
45
45
- . boolean ( "compress " ) . describe ( "compress " , "enable gzip compression " )
46
+ . boolean ( "history-api-fallback " ) . describe ( "history-api-fallback " , "Fallback to /index.html for Single Page Applications. " )
46
47
47
- . describe ( "port" , "The port" ) . default ( "port ", 8080 )
48
+ . boolean ( "compress" ) . describe ( "compress ", "enable gzip compression" )
48
49
49
- . describe ( "public " , "The public hostname/ip address of the server " )
50
+ . boolean ( "open" ) . describe ( "open " , "Open default browser " )
50
51
51
- . describe ( "host" , "The hostname/ip address the server will bind to" ) . default ( "host" , "localhost" ) ;
52
+ . describe ( "port" , "The port" ) . default ( "port" , 8080 )
53
+
54
+ . describe ( "public" , "The public hostname/ip address of the server" )
55
+
56
+ . describe ( "host" , "The hostname/ip address the server will bind to" ) . default ( "host" , "localhost" ) ;
52
57
53
58
require ( "webpack/bin/config-optimist" ) ( optimist ) ;
54
59
55
60
var argv = optimist . argv ;
56
61
57
- var wpOpt = require ( "webpack/bin/convert-argv" ) ( optimist , argv , { outputFilename : "/bundle.js" } ) ;
62
+ var wpOpt = require ( "webpack/bin/convert-argv" ) ( optimist , argv , {
63
+ outputFilename : "/bundle.js"
64
+ } ) ;
58
65
var firstWpOpt = Array . isArray ( wpOpt ) ? wpOpt [ 0 ] : wpOpt ;
59
66
60
67
var options = wpOpt . devServer || firstWpOpt . devServer || { } ;
@@ -84,6 +91,14 @@ if(!options.filename)
84
91
85
92
if ( ! options . watchOptions )
86
93
options . watchOptions = firstWpOpt . watchOptions ;
94
+
95
+ if ( argv [ "stdin" ] ) {
96
+ process . stdin . on ( 'end' , function ( ) {
97
+ process . exit ( 0 ) ;
98
+ } ) ;
99
+ process . stdin . resume ( ) ;
100
+ }
101
+
87
102
if ( ! options . watchDelay && ! options . watchOptions ) // TODO remove in next major version
88
103
options . watchDelay = firstWpOpt . watchDelay ;
89
104
@@ -97,7 +112,9 @@ if(argv["content-base"]) {
97
112
else if ( ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( options . contentBase ) )
98
113
options . contentBase = path . resolve ( options . contentBase ) ;
99
114
} else if ( argv [ "content-base-target" ] ) {
100
- options . contentBase = { target : argv [ "content-base-target" ] } ;
115
+ options . contentBase = {
116
+ target : argv [ "content-base-target" ]
117
+ } ;
101
118
} else if ( ! options . contentBase ) {
102
119
options . contentBase = process . cwd ( ) ;
103
120
}
@@ -142,6 +159,9 @@ if(argv["history-api-fallback"])
142
159
if ( argv [ "compress" ] )
143
160
options . compress = true ;
144
161
162
+ if ( argv [ "open" ] )
163
+ options . open = true ;
164
+
145
165
var protocol = options . https ? "https" : "http" ;
146
166
147
167
if ( options . inline ) {
@@ -161,16 +181,19 @@ if(options.inline) {
161
181
}
162
182
163
183
new Server ( webpack ( wpOpt ) , options ) . listen ( options . port , options . host , function ( err ) {
184
+ var uri = protocol + "://" + options . host + ":" + options . port + "/" ;
185
+ if ( ! options . inline )
186
+ uri += "webpack-dev-server/" ;
187
+
164
188
if ( err ) throw err ;
165
- if ( options . inline )
166
- console . log ( protocol + "://" + options . host + ":" + options . port + "/" ) ;
167
- else
168
- console . log ( protocol + "://" + options . host + ":" + options . port + "/webpack-dev-server/" ) ;
189
+ console . log ( uri ) ;
169
190
console . log ( "webpack result is served from " + options . publicPath ) ;
170
191
if ( typeof options . contentBase === "object" )
171
192
console . log ( "requests are proxied to " + options . contentBase . target ) ;
172
193
else
173
194
console . log ( "content is served from " + options . contentBase ) ;
174
195
if ( options . historyApiFallback )
175
196
console . log ( "404s will fallback to %s" , options . historyApiFallback . index || "/index.html" ) ;
197
+ if ( options . open )
198
+ open ( uri ) ;
176
199
} ) ;
0 commit comments