mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +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 pify from 'pify'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { resolve, join, dirname, sep } from 'path'
|
import { resolve, join, dirname, sep } from 'path'
|
||||||
import { isUrl, promisifyRoute } from './utils'
|
import { isUrl, promisifyRoute, waitFor } from './utils'
|
||||||
import { minify } from 'html-minifier'
|
import { minify } from 'html-minifier'
|
||||||
const debug = require('debug')('nuxt:generate')
|
const debug = require('debug')('nuxt:generate')
|
||||||
const copy = pify(fs.copy)
|
const copy = pify(fs.copy)
|
||||||
@ -16,6 +16,7 @@ const mkdirp = pify(fs.mkdirp)
|
|||||||
const defaults = {
|
const defaults = {
|
||||||
dir: 'dist',
|
dir: 'dist',
|
||||||
routes: [],
|
routes: [],
|
||||||
|
interval: 0,
|
||||||
minify: {
|
minify: {
|
||||||
collapseBooleanAttributes: true,
|
collapseBooleanAttributes: true,
|
||||||
collapseWhitespace: true,
|
collapseWhitespace: true,
|
||||||
@ -89,28 +90,13 @@ export default function () {
|
|||||||
this.routes.push(route)
|
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
|
let routes = this.routes
|
||||||
return co(function * () {
|
return co(function * () {
|
||||||
while (routes.length) {
|
while (routes.length) {
|
||||||
|
let n = 0
|
||||||
yield routes.splice(0, 500).map((route) => {
|
yield routes.splice(0, 500).map((route) => {
|
||||||
return co(function * () {
|
return co(function * () {
|
||||||
if(self.options.generate.wait) {
|
yield waitFor(n++ * self.options.generate.interval)
|
||||||
yield timer()
|
|
||||||
}
|
|
||||||
var { html } = yield self.renderRoute(route, { _generate: true })
|
var { html } = yield self.renderRoute(route, { _generate: true })
|
||||||
html = minify(html, self.options.generate.minify)
|
html = minify(html, self.options.generate.minify)
|
||||||
var path = join(route, sep, 'index.html') // /about -> /about/index.html
|
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/2',
|
||||||
'/users/3'
|
'/users/3'
|
||||||
],
|
],
|
||||||
wait : 1000
|
interval: 200
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user