This commit is contained in:
Pooya Parsa 2017-06-19 20:17:31 +04:30
parent e0ea1dd1ee
commit a594606f85
10 changed files with 31 additions and 17 deletions

View File

@ -45,10 +45,12 @@ export default class Builder extends Tapable {
async build () {
// Avoid calling build() method multiple times when dev:true
/* istanbul ignore if */
if (this._buildStatus === STATUS.BUILD_DONE && this.options.dev) {
return this
}
// If building
/* istanbul ignore if */
if (this._buildStatus === STATUS.BUILDING) {
return new Promise((resolve) => {
setTimeout(() => {
@ -287,6 +289,7 @@ export default class Builder extends Tapable {
// Run after each compile
this.compiler.plugin('done', stats => {
// Don't reload failed builds
/* istanbul ignore if */
if (stats.hasErrors() || stats.hasWarnings()) {
return
}
@ -311,6 +314,7 @@ export default class Builder extends Tapable {
} else {
// Build and watch for changes
compiler.watch(this.options.watchers.webpack, (err) => {
/* istanbul ignore if */
if (err) {
return reject(err)
}
@ -326,6 +330,7 @@ export default class Builder extends Tapable {
if (err) return console.error(err) // eslint-disable-line no-console
// Show build stats for production
console.log(stats.toString(this.webpackStats)) // eslint-disable-line no-console
/* istanbul ignore if */
if (stats.hasErrors()) {
return reject(new Error('Webpack build exited with errors'))
}

View File

@ -41,6 +41,7 @@ export default class Generator extends Tapable {
debug('Destination folder cleaned')
// Copy static and built files
/* istanbul ignore if */
if (fs.existsSync(srcStaticPath)) {
await copy(srcStaticPath, distPath)
}

View File

@ -18,6 +18,7 @@ import { styleLoader, extractStyles } from './helpers'
export default function webpackBaseConfig ({ isClient, isServer }) {
const nodeModulesDir = join(__dirname, '..', 'node_modules')
/* istanbul ignore if */
if (!Array.isArray(this.options.build.postcss)) {
this.options.build.postcss = [
autoprefixer({

View File

@ -57,6 +57,7 @@ export default function webpackClientConfig () {
})
// Webpack common plugins
/* istanbul ignore if */
if (!Array.isArray(config.plugins)) {
config.plugins = []
}

View File

@ -105,6 +105,7 @@ export function r () {
export function flatRoutes (router, path = '', routes = []) {
router.forEach((r) => {
if (!r.path.includes(':') && !r.path.includes('*')) {
/* istanbul ignore if */
if (r.children) {
flatRoutes(r.children, path + r.path + '/', routes)
} else {

View File

@ -38,6 +38,7 @@ export default class ModuleContainer extends Tapable {
const srcPath = path.parse(src)
/* istanbul ignore if */
if (!src || typeof src !== 'string' || !fs.existsSync(src)) {
/* istanbul ignore next */
debug('[nuxt] invalid template', template)
return
}

View File

@ -38,7 +38,7 @@ export default class Nuxt extends Tapable {
return this
}
errorHandler () {
errorHandler /* istanbul ignore next */ () {
// Silent
if (this.options.errorHandler === false) {
return

View File

@ -36,6 +36,7 @@ export default function Options (_options) {
}
// Ignore publicPath on dev
/* istanbul ignore if */
if (options.dev && isUrl(options.build.publicPath)) {
options.build.publicPath = defaultOptions.build.publicPath
}

View File

@ -1,17 +1,16 @@
import ansiHTML from 'ansi-html'
import serialize from 'serialize-javascript'
import generateETag from 'etag'
import fresh from 'fresh'
import Tapable from 'tappable'
import pify from 'pify'
import serveStatic from 'serve-static'
import compression from 'compression'
import _ from 'lodash'
import { resolve, join } from 'path'
import fs from 'fs-extra'
import { createBundleRenderer } from 'vue-server-renderer'
import { getContext, setAnsiColors, encodeHtml } from 'utils'
import Debug from 'debug'
import ansiHTML from "ansi-html";
import serialize from "serialize-javascript";
import generateETag from "etag";
import fresh from "fresh";
import Tapable from "tappable";
import pify from "pify";
import compression from "compression";
import _ from "lodash";
import { join, resolve } from "path";
import fs from "fs-extra";
import { createBundleRenderer } from "vue-server-renderer";
import { encodeHtml, getContext, setAnsiColors } from "utils";
import Debug from "debug";
const debug = Debug('nuxt:render')
debug.color = 4 // Force blue color
@ -46,6 +45,7 @@ export default class Renderer extends Tapable {
}
// Initialize
/* istanbul ignore if */
if (nuxt.initialized) {
// If nuxt already initialized
this._ready = this.ready().catch(this.nuxt.errorHandler)
@ -59,6 +59,7 @@ export default class Renderer extends Tapable {
}
async ready () {
/* istanbul ignore if */
if (this._ready) {
return this._ready
}
@ -122,6 +123,7 @@ export default class Renderer extends Tapable {
}
this.resources[rawKey] = rawData
data = transform(rawData)
/* istanbul ignore if */
if (!data) {
return // Invalid data ?
}
@ -337,10 +339,9 @@ export default class Renderer extends Tapable {
const { window } = await jsdom.JSDOM.fromURL(url, options)
// If Nuxt could not be loaded (error from the server-side)
const nuxtExists = window.document.body.innerHTML.includes('window.__NUXT__')
/* istanbul ignore if */
if (!nuxtExists) {
/* istanbul ignore next */
let error = new Error('Could not load the nuxt app')
/* istanbul ignore next */
error.body = window.document.body.innerHTML
throw error
}

View File

@ -9,6 +9,7 @@ class Server {
this.options = nuxt.options
// Initialize
/* istanbul ignore if */
if (nuxt.initialized) {
// If nuxt already initialized
this._ready = this.ready().catch(this.nuxt.errorHandler)
@ -22,6 +23,7 @@ class Server {
}
async ready () {
/* istanbul ignore if */
if (this._ready) {
return this._ready
}