mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Add generate.interval
This commit is contained in:
parent
296ea8ad4e
commit
10d18bc454
@ -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
|
||||
|
2
test/fixtures/basic/nuxt.config.js
vendored
2
test/fixtures/basic/nuxt.config.js
vendored
@ -5,6 +5,6 @@ module.exports = {
|
||||
'/users/2',
|
||||
'/users/3'
|
||||
],
|
||||
wait : 1000
|
||||
interval: 200
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user