Add performance option

This commit is contained in:
Sébastien Chopin 2017-02-21 17:39:29 +00:00
parent 10c4b1550f
commit 6cc1231eb2
3 changed files with 14 additions and 5 deletions

View File

@ -41,6 +41,10 @@ class Nuxt {
extendRoutes: null, extendRoutes: null,
scrollBehavior: null scrollBehavior: null
}, },
performance: {
gzip: true,
prefetch: true
},
build: {} build: {}
} }
// Sanitization // Sanitization

View File

@ -30,7 +30,8 @@ export function render (req, res) {
// Call webpack middleware only in development // Call webpack middleware only in development
yield self.webpackDevMiddleware(req, res) yield self.webpackDevMiddleware(req, res)
yield self.webpackHotMiddleware(req, res) yield self.webpackHotMiddleware(req, res)
} else { }
if (!self.dev && self.options.performance.gzip === true) {
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

View File

@ -61,13 +61,17 @@ export default function () {
// Add defer to scripts // Add defer to scripts
new ScriptExtHtmlWebpackPlugin({ new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'defer' defaultAttribute: 'defer'
}),
// Add prefetch code-splitted routes
new PreloadWebpackPlugin({
rel: 'prefetch'
}) })
]) ])
if (this.options.performance.prefetch === true) {
// Add prefetch code-splitted routes
config.plugins.push(
new PreloadWebpackPlugin({
rel: 'prefetch'
})
)
}
// client bundle progress bar // client bundle progress bar
config.plugins.push( config.plugins.push(
new ProgressBarPlugin() new ProgressBarPlugin()