mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Merge pull request #768 from jroxendal/feature-routepayload
[Feature: generate] optimize rendering step in generate
This commit is contained in:
commit
c2592a2663
@ -61,6 +61,7 @@ export function getContext (context, app) {
|
||||
app: app,
|
||||
<%= (store ? 'store: context.store,' : '') %>
|
||||
route: (context.to ? context.to : context.route),
|
||||
payload : context.payload,
|
||||
error: context.error,
|
||||
base: '<%= router.base %>',
|
||||
env: <%= JSON.stringify(env) %>
|
||||
|
@ -78,26 +78,32 @@ export default async function () {
|
||||
process.exit(1)
|
||||
throw e // eslint-disable-line no-unreachable
|
||||
}
|
||||
/*
|
||||
** Generate html files from routes
|
||||
*/
|
||||
}
|
||||
function decorateWithPayloads (routes) {
|
||||
let routeMap = _(routes).map((route) => {
|
||||
return [route, {route, payload: {}}]
|
||||
}).fromPairs().value()
|
||||
generateRoutes.forEach((route) => {
|
||||
if (this.routes.indexOf(route) < 0) {
|
||||
this.routes.push(route)
|
||||
// route argument is either a string or like {route : "/my_route/1"}
|
||||
route = _.isString(route) ? route : route.route
|
||||
if (!routeMap[route]) {
|
||||
routeMap[route] = {route, payload: route.payload}
|
||||
}
|
||||
})
|
||||
return _.values(routeMap)
|
||||
}
|
||||
/*
|
||||
** Generate only index.html for router.mode = 'hash'
|
||||
*/
|
||||
let routes = (this.options.router.mode === 'hash') ? ['/'] : this.routes
|
||||
let routes = (this.options.router.mode === 'hash') ? [{route: '/'}] : decorateWithPayloads(this.routes)
|
||||
|
||||
while (routes.length) {
|
||||
let n = 0
|
||||
await Promise.all(routes.splice(0, 500).map(async (route) => {
|
||||
await Promise.all(routes.splice(0, 500).map(async ({route, payload}) => {
|
||||
await waitFor(n++ * this.options.generate.interval)
|
||||
let html
|
||||
try {
|
||||
const res = await this.renderRoute(route, { _generate: true })
|
||||
const res = await this.renderRoute(route, { _generate: true, payload })
|
||||
html = res.html
|
||||
if (res.error) {
|
||||
errors.push({ type: 'handled', route, error: res.error })
|
||||
|
Loading…
Reference in New Issue
Block a user