mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
f234c071c9
@ -4,9 +4,17 @@
|
|||||||
process.env.DEBUG = 'nuxt:*'
|
process.env.DEBUG = 'nuxt:*'
|
||||||
|
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
var without = require('lodash').without
|
||||||
var Nuxt = require('../')
|
var Nuxt = require('../')
|
||||||
var resolve = require('path').resolve
|
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 rootDir = resolve(process.argv.slice(2)[0] || '.')
|
||||||
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
|
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.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
|
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
||||||
var nuxt = new Nuxt(options)
|
var nuxt = new Nuxt(options)
|
||||||
nuxt.build()
|
nuxt.build()
|
||||||
|
@ -40,6 +40,7 @@ const r = function () {
|
|||||||
debug.color = 2
|
debug.color = 2
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
|
analyze: false,
|
||||||
filenames: {
|
filenames: {
|
||||||
css: 'style.css',
|
css: 'style.css',
|
||||||
vendor: 'vendor.bundle.js',
|
vendor: 'vendor.bundle.js',
|
||||||
|
@ -20,7 +20,7 @@ export function render (req, res) {
|
|||||||
}
|
}
|
||||||
const self = this
|
const self = this
|
||||||
const context = getContext(req, res)
|
const context = getContext(req, res)
|
||||||
co(function * () {
|
return co(function * () {
|
||||||
if (self.dev) {
|
if (self.dev) {
|
||||||
// Call webpack middlewares only in development
|
// Call webpack middlewares only in development
|
||||||
yield self.webpackDevMiddleware(req, res)
|
yield self.webpackDevMiddleware(req, res)
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import { each } from 'lodash'
|
import { each } from 'lodash'
|
||||||
import webpack from 'webpack'
|
import webpack from 'webpack'
|
||||||
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
import ExtractTextPlugin from 'extract-text-webpack-plugin'
|
||||||
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
||||||
import base from './base.config.js'
|
import base from './base.config.js'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Webpack Client Config
|
| Webpack Client Config
|
||||||
@ -79,5 +79,15 @@ export default function () {
|
|||||||
isClient: true
|
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
|
return config
|
||||||
}
|
}
|
||||||
|
4
test/fixtures/with-config/nuxt.config.js
vendored
4
test/fixtures/with-config/nuxt.config.js
vendored
@ -20,6 +20,10 @@ module.exports = {
|
|||||||
string: 'Nuxt.js'
|
string: 'Nuxt.js'
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
analyze: {
|
||||||
|
analyzerMode: 'disabled',
|
||||||
|
generateStatsFile: true
|
||||||
|
},
|
||||||
extend (config, options) {
|
extend (config, options) {
|
||||||
config.devtool = 'nosources-source-map'
|
config.devtool = 'nosources-source-map'
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,11 @@ test('/test/about-bis (added with extendRoutes)', async t => {
|
|||||||
t.true(html.includes('<h1>About page</h1>'))
|
t.true(html.includes('<h1>About page</h1>'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
test.after('Closing server and nuxt.js', t => {
|
test.after('Closing server and nuxt.js', t => {
|
||||||
server.close()
|
server.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user