From d17b12eac57df8d28b06e88437ca3812deed5408 Mon Sep 17 00:00:00 2001 From: Mirodil Date: Sun, 22 Jan 2017 18:35:44 -0500 Subject: [PATCH 1/3] make it more compatible with other frameworks make it use able with async with await --- lib/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/render.js b/lib/render.js index e5b47495cf..1b7c1f2dce 100644 --- a/lib/render.js +++ b/lib/render.js @@ -20,7 +20,7 @@ export function render (req, res) { } const self = this const context = getContext(req, res) - co(function * () { + return co(function * () { if (self.dev) { // Call webpack middlewares only in development yield self.webpackDevMiddleware(req, res) From 7552da1453a8079b9f321dceb6d6f22fca645951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 23 Jan 2017 17:55:39 +0100 Subject: [PATCH 2/3] Add analyse option --- bin/nuxt-build | 11 +++++++++++ lib/build.js | 1 + lib/webpack/client.config.js | 12 +++++++++++- test/fixtures/with-config/nuxt.config.js | 4 ++++ test/with-config.test.js | 5 +++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bin/nuxt-build b/bin/nuxt-build index 7f6e057169..50e2fbe62f 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -4,9 +4,17 @@ process.env.DEBUG = 'nuxt:*' var fs = require('fs') +var without = require('lodash').without var Nuxt = require('../') var resolve = require('path').resolve +// --analyze option +var analyzeBuild = false +if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== -1) { + analyzeBuild = true + process.argv = without(process.argv, '--analyze', '-a') +} + var rootDir = resolve(process.argv.slice(2)[0] || '.') var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js') @@ -19,6 +27,9 @@ if (typeof options.rootDir !== 'string') { } options.dev = false // Create production build when calling `nuxt build` +options.build = options.build || {} +options.build.analyze = analyzeBuild + console.log('[nuxt] Building...') // eslint-disable-line no-console var nuxt = new Nuxt(options) nuxt.build() diff --git a/lib/build.js b/lib/build.js index 3635e3526b..743bb57b1d 100644 --- a/lib/build.js +++ b/lib/build.js @@ -40,6 +40,7 @@ const r = function () { debug.color = 2 const defaults = { + analyze: false, filenames: { css: 'style.css', vendor: 'vendor.bundle.js', diff --git a/lib/webpack/client.config.js b/lib/webpack/client.config.js index 6c2e68549d..85f12a0e51 100644 --- a/lib/webpack/client.config.js +++ b/lib/webpack/client.config.js @@ -3,9 +3,9 @@ import { each } from 'lodash' import webpack from 'webpack' import ExtractTextPlugin from 'extract-text-webpack-plugin' +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' import base from './base.config.js' import { resolve } from 'path' - /* |-------------------------------------------------------------------------- | Webpack Client Config @@ -79,5 +79,15 @@ export default function () { isClient: true }) } + // Webpack Bundle Analyzer + if (!this.dev && this.options.build.analyze) { + let options = {} + if (typeof this.options.build.analyze === 'object') { + options = this.options.build.analyze + } + config.plugins.push( + new BundleAnalyzerPlugin(options) + ) + } return config } diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 3d97739dad..e085010524 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -20,6 +20,10 @@ module.exports = { string: 'Nuxt.js' }, build: { + analyze: { + analyzerMode: 'disabled', + generateStatsFile: true + }, extend (config, options) { config.devtool = 'nosources-source-map' } diff --git a/test/with-config.test.js b/test/with-config.test.js index ba7e145c69..42c4da447a 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -54,6 +54,11 @@ test('/test/about-bis (added with extendRoutes)', async t => { t.true(html.includes('

About page

')) }) +test('Check stats.json generated by build.analyze', t => { + const stats = require(resolve(__dirname, 'fixtures/with-config/.nuxt/dist/stats.json')) + t.is(stats.assets.length, 10) +}) + // Close server and ask nuxt to stop listening to file changes test.after('Closing server and nuxt.js', t => { server.close() From e9740e4e277a29f011fe317677301f659da09ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 23 Jan 2017 17:55:53 +0100 Subject: [PATCH 3/3] Upgrade dependencies --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e1e86b059b..60ea6875bb 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ }, "dependencies": { "ansi-html": "^0.0.7", - "autoprefixer": "^6.6.0", + "autoprefixer": "^6.7.0", "babel-core": "^6.22.1", "babel-loader": "^6.2.10", "babel-plugin-array-includes": "^2.0.3", @@ -80,21 +80,22 @@ "vue-template-compiler": "^2.1.10", "vuex": "^2.1.1", "webpack": "^2.2.0", + "webpack-bundle-analyzer": "^2.2.1", "webpack-dev-middleware": "^1.9.0", - "webpack-hot-middleware": "^2.14.0" + "webpack-hot-middleware": "^2.15.0" }, "devDependencies": { "ava": "^0.17.0", "babel-eslint": "^7.1.1", "codecov": "^1.0.1", "copy-webpack-plugin": "^4.0.1", - "eslint": "^3.10.2", + "eslint": "^3.14.0", "eslint-config-standard": "^6.2.1", "eslint-plugin-html": "^1.7.0", "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "^2.0.1", "finalhandler": "^0.5.1", - "jsdom": "^9.8.3", + "jsdom": "^9.9.1", "json-loader": "^0.5.4", "nyc": "^10.1.2", "request": "^2.79.0",