Add generate.interval

This commit is contained in:
Sebastien Chopin 2017-04-25 15:00:42 +02:00
parent 296ea8ad4e
commit 10d18bc454
2 changed files with 5 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import co from 'co'
import pify from 'pify'
import _ from 'lodash'
import { resolve, join, dirname, sep } from 'path'
import { isUrl, promisifyRoute } from './utils'
import { isUrl, promisifyRoute, waitFor } from './utils'
import { minify } from 'html-minifier'
const debug = require('debug')('nuxt:generate')
const copy = pify(fs.copy)
@ -16,6 +16,7 @@ const mkdirp = pify(fs.mkdirp)
const defaults = {
dir: 'dist',
routes: [],
interval: 0,
minify: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
@ -89,28 +90,13 @@ export default function () {
this.routes.push(route)
}
})
var n = 0
function timer () {
let promise = new Promise(
(resolve, reject) => {
setTimeout( () => {
resolve()
}, self.options.generate.wait * n)
}
)
n++
return promise
}
let routes = this.routes
return co(function * () {
while (routes.length) {
let n = 0
yield routes.splice(0, 500).map((route) => {
return co(function * () {
if(self.options.generate.wait) {
yield timer()
}
yield waitFor(n++ * self.options.generate.interval)
var { html } = yield self.renderRoute(route, { _generate: true })
html = minify(html, self.options.generate.minify)
var path = join(route, sep, 'index.html') // /about -> /about/index.html

View File

@ -5,6 +5,6 @@ module.exports = {
'/users/2',
'/users/3'
],
wait : 1000
interval: 200
}
}