Skip to content

Commit

Permalink
perf: render pages in parallel (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaiyan-dev committed Dec 8, 2022
1 parent 86cc157 commit 78f737c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
31 changes: 16 additions & 15 deletions packages/bundler-vite/src/build/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CreateVueAppFunction } from '@vuepress/client'
import type { App, Bundler } from '@vuepress/core'
import { colors, debug, fs, importFile, withSpinner } from '@vuepress/utils'
import { debug, fs, importFile, withSpinner } from '@vuepress/utils'
import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup'
import { build as viteBuild } from 'vite'
import { resolveViteConfig } from '../resolveViteConfig.js'
Expand Down Expand Up @@ -73,20 +73,21 @@ export const build = async (
const { renderToString } = await import('vue/server-renderer')

// pre-render pages to html files
for (const page of app.pages) {
if (spinner) spinner.text = `Rendering pages ${colors.magenta(page.path)}`
await renderPage({
app,
page,
vueApp,
vueRouter,
renderToString,
ssrTemplate,
output: clientOutput.output,
outputEntryChunk: clientEntryChunk,
outputCssAsset: clientCssAsset,
})
}
await Promise.all(
app.pages.map((page) =>
renderPage({
app,
page,
vueApp,
vueRouter,
renderToString,
ssrTemplate,
output: clientOutput.output,
outputEntryChunk: clientEntryChunk,
outputCssAsset: clientCssAsset,
})
)
)
})

// keep the server bundle files in debug mode
Expand Down
41 changes: 17 additions & 24 deletions packages/bundler-webpack/src/build/build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { CreateVueAppFunction } from '@vuepress/client'
import type { App, Bundler } from '@vuepress/core'
import {
colors,
debug,
fs,
importFileDefault,
withSpinner,
} from '@vuepress/utils'
import { debug, fs, importFileDefault, withSpinner } from '@vuepress/utils'
import webpack from 'webpack'
import { resolveWebpackConfig } from '../resolveWebpackConfig.js'
import type { WebpackBundlerOptions } from '../types.js'
Expand Down Expand Up @@ -96,23 +90,22 @@ export const build = async (
const { renderToString } = await import('vue/server-renderer')

// pre-render pages to html files
for (const page of app.pages) {
if (spinner) {
spinner.text = `Rendering pages ${colors.magenta(page.path)}`
}
await renderPage({
app,
page,
vueApp,
vueRouter,
renderToString,
ssrTemplate,
allFilesMeta,
initialFilesMeta,
asyncFilesMeta,
moduleFilesMetaMap,
})
}
await Promise.all(
app.pages.map((page) =>
renderPage({
app,
page,
vueApp,
vueRouter,
renderToString,
ssrTemplate,
allFilesMeta,
initialFilesMeta,
asyncFilesMeta,
moduleFilesMetaMap,
})
)
)
})

// keep the server bundle files in debug mode
Expand Down

0 comments on commit 78f737c

Please sign in to comment.