diff --git a/lib/generate.js b/lib/generate.js index 3a930de3bc..228f617a32 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -86,31 +86,32 @@ export default async function () { this.routes.push(route) } }) - let n = 0 - for (let route of this.routes) { - await waitFor(n++ * self.options.generate.interval) - try { - var { html, error } = await self.renderRoute(route, { _generate: true }) - if (error) { - errors.push({ type: 'handled', route, error }) + let routes = this.routes + while (routes.length) { + let n = 0 + await Promise.all(routes.splice(0, 500).map(async (route) => { + await waitFor(n++ * self.options.generate.interval) + try { + var { html, error } = await self.renderRoute(route, { _generate: true }) + if (error) { + errors.push({ type: 'handled', route, error }) + } + } catch (err) { + errors.push({ type: 'unhandled', route, error: err }) } - } catch (err) { - errors.push({ type: 'unhandled', route, error: err }) - continue - } - try { - var minifiedHtml = minify(html, self.options.generate.minify) - } catch (err) { - let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`) - errors.push({ type: 'unhandled', route, error: minifyErr }) - continue - } - var path = join(route, sep, 'index.html') // /about -> /about/index.html - debug('Generate file: ' + path) - path = join(distPath, path) - // Make sure the sub folders are created - await mkdirp(dirname(path)) - await writeFile(path, minifiedHtml, 'utf8') + try { + var minifiedHtml = minify(html, self.options.generate.minify) + } catch (err) { + let minifyErr = new Error(`HTML minification failed. Make sure the route generates valid HTML. Failed HTML:\n ${html}`) + errors.push({ type: 'unhandled', route, error: minifyErr }) + } + var path = join(route, sep, 'index.html') // /about -> /about/index.html + debug('Generate file: ' + path) + path = join(distPath, path) + // Make sure the sub folders are created + await mkdirp(dirname(path)) + await writeFile(path, minifiedHtml, 'utf8') + })) } // Add .nojekyll file to let Github Pages add the _nuxt/ folder // https://help.github.com/articles/files-that-start-with-an-underscore-are-missing/ diff --git a/lib/utils.js b/lib/utils.js index edea410fdb..2ffc5aee7a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -21,7 +21,7 @@ export function setAnsiColors (ansiHTML) { }) } -export function * waitFor (ms) { +export async function waitFor (ms) { return new Promise(function (resolve) { setTimeout(resolve, (ms || 0)) }) diff --git a/test/utils.test.js b/test/utils.test.js index 3e09d1af1f..34befd360f 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -28,9 +28,9 @@ test('setAnsiColors', t => { t.pass() }) -test('waitFor', function * (t) { +test('waitFor', async (t) => { let s = Date.now() - yield utils.waitFor(100) + await utils.waitFor(100) t.true(Date.now() - s >= 100) })