Skip to content

Commit

Permalink
feat($core): Improve VuePress build time (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
kefranabg committed Mar 10, 2020
1 parent 0aadf05 commit 76da780
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
20 changes: 12 additions & 8 deletions packages/@vuepress/core/lib/node/Page.js
Expand Up @@ -286,13 +286,17 @@ module.exports = class Page {
*/

async enhance (enhancers) {
for (const { name: pluginName, value: enhancer } of enhancers) {
try {
await enhancer(this)
} catch (error) {
console.log(error)
throw new Error(`[${pluginName}] execute extendPageData failed.`)
}
}
return Promise.all(
enhancers.map(
async ({ value: enhancer, name: pluginName }) => {
try {
await enhancer(this)
} catch (error) {
console.log(error)
throw new Error(`[${pluginName}] execute extendPageData failed.`)
}
}
)
)
}
}
13 changes: 7 additions & 6 deletions packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js
Expand Up @@ -111,11 +111,11 @@ describe('Page', () => {
page = new Page({ path: '/' }, app)
enhancers = [
{
pluginName: 'foo',
name: 'foo',
value: jest.fn()
},
{
pluginName: 'foo',
name: 'bar',
value: jest.fn()
}
]
Expand All @@ -130,21 +130,22 @@ describe('Page', () => {

test('should loop over sync and async enhancers', async () => {
const mixedEnhancers = [...enhancers, {
pluginName: 'blog',
name: 'blog',
value: jest.fn().mockResolvedValue({})
}]
await page.enhance(mixedEnhancers)

return mixedEnhancers.map(enhancer => expect(enhancer.value).toHaveBeenCalled())
})

test('should log when enhancing when failing', async () => {
test('should log and throw an error when enhancing fails', async () => {
const error = { errorMessage: 'this is an error message' }
const pluginName = 'error-plugin'

await expect(page.enhance([{
pluginName: 'error-plugin',
name: pluginName,
value: jest.fn().mockRejectedValue(error)
}])).rejects.toThrow()
}])).rejects.toThrowError(`[${pluginName}] execute extendPageData failed.`)

expect(console.log).toHaveBeenCalledWith(error)
})
Expand Down
10 changes: 3 additions & 7 deletions packages/@vuepress/core/lib/node/build/index.js
Expand Up @@ -89,10 +89,9 @@ module.exports = class Build extends EventEmitter {
// render pages
logger.wait('Rendering static HTML...')

const pagePaths = []
for (const page of this.context.pages) {
pagePaths.push(await this.renderPage(page))
}
const pagePaths = await Promise.all(
this.context.pages.map(page => this.renderPage(page))
)

This comment has been minimized.

Copy link
@8zf

8zf Jul 27, 2020

when page number is large (like 300+), it will cause javascript oom


readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
Expand Down Expand Up @@ -134,9 +133,6 @@ module.exports = class Build extends EventEmitter {

async renderPage (page) {
const pagePath = decodeURIComponent(page.path)
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
process.stdout.write(`Rendering page: ${pagePath}`)

// #565 Avoid duplicate description meta at SSR.
const meta = (page.frontmatter && page.frontmatter.meta || []).filter(item => item.name !== 'description')
Expand Down

0 comments on commit 76da780

Please sign in to comment.