File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ var optimist = require("optimist")
42
42
43
43
. boolean ( "history-api-fallback" ) . describe ( "history-api-fallback" , "Fallback to /index.html for Single Page Applications." )
44
44
45
+ . boolean ( "compress" ) . describe ( "compress" , "enable gzip compression" )
46
+
45
47
. describe ( "port" , "The port" ) . default ( "port" , 8080 )
46
48
47
49
. describe ( "host" , "The hostname/ip address the server will bind to" ) . default ( "host" , "localhost" ) ;
@@ -132,6 +134,9 @@ if(argv["inline"])
132
134
if ( argv [ "history-api-fallback" ] )
133
135
options . historyApiFallback = true ;
134
136
137
+ if ( argv [ "compress" ] )
138
+ options . compress = true ;
139
+
135
140
var protocol = options . https ? "https" : "http" ;
136
141
137
142
if ( options . inline ) {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ var fs = require("fs");
2
2
var path = require ( "path" ) ;
3
3
var webpackDevMiddleware = require ( "webpack-dev-middleware" ) ;
4
4
var express = require ( "express" ) ;
5
+ var compress = require ( "compression" ) ;
5
6
var socketio = require ( "socket.io" ) ;
6
7
var StreamCache = require ( "stream-cache" ) ;
7
8
var http = require ( "http" ) ;
@@ -110,6 +111,13 @@ function Server(compiler, options) {
110
111
} . bind ( this ) ) ;
111
112
112
113
var features = {
114
+ compress : function ( ) {
115
+ if ( options . compress ) {
116
+ // Enable gzip compression.
117
+ app . use ( compress ( ) ) ;
118
+ }
119
+ } . bind ( this ) ,
120
+
113
121
proxy : function ( ) {
114
122
if ( options . proxy ) {
115
123
if ( ! Array . isArray ( options . proxy ) ) {
@@ -213,6 +221,9 @@ function Server(compiler, options) {
213
221
defaultFeatures . push ( "magicHtml" ) ;
214
222
if ( options . contentBase !== false )
215
223
defaultFeatures . push ( "contentBase" ) ;
224
+ // compress is placed last and uses unshift so that it will be the first middleware used
225
+ if ( options . compress )
226
+ defaultFeatures . unshift ( "compress" ) ;
216
227
217
228
( options . features || defaultFeatures ) . forEach ( function ( feature ) {
218
229
features [ feature ] ( ) ;
Original file line number Diff line number Diff line change 7
7
"webpack" : " ^1.3.0"
8
8
},
9
9
"dependencies" : {
10
+ "compression" : " ^1.5.2" ,
10
11
"connect-history-api-fallback" : " 1.1.0" ,
11
12
"express" : " ^4.13.3" ,
12
13
"http-proxy" : " ^1.11.2" ,
You can’t perform that action at this time.
0 commit comments