add gzip configuration

This commit is contained in:
Alexandre Chopin 2017-03-25 12:57:34 +01:00
parent 77439223cf
commit c9784651e9
2 changed files with 6 additions and 6 deletions

View File

@ -41,7 +41,9 @@ class Nuxt {
scrollBehavior: null scrollBehavior: null
}, },
performance: { performance: {
gzip: true, gzip: {
threshold: 0
},
prefetch: true prefetch: true
}, },
build: {} build: {}
@ -73,10 +75,8 @@ class Nuxt {
maxAge: (this.dev ? 0 : '1y') // 1 year in production maxAge: (this.dev ? 0 : '1y') // 1 year in production
})) }))
// gzip for production // gzip for production
if (!this.dev) { if (!this.dev && this.options.performance.gzip) {
this.gzipMiddleware = pify(compression({ this.gzipMiddleware = pify(compression(this.options.performance.gzip))
threshold: 0
}))
} }
// Add this.Server Class // Add this.Server Class
this.Server = Server this.Server = Server

View File

@ -31,7 +31,7 @@ export function render (req, res) {
yield self.webpackDevMiddleware(req, res) yield self.webpackDevMiddleware(req, res)
yield self.webpackHotMiddleware(req, res) yield self.webpackHotMiddleware(req, res)
} }
if (!self.dev && self.options.performance.gzip === true) { if (!self.dev && self.options.performance.gzip) {
yield self.gzipMiddleware(req, res) yield self.gzipMiddleware(req, res)
} }
// If base in req.url, remove it for the middleware and vue-router // If base in req.url, remove it for the middleware and vue-router