Skip to content

Commit 83d68f7

Browse files
committed
perf($core): limit number of static html pages rendered to 50 active
1 parent 0ecd7dc commit 83d68f7

File tree

1 file changed

+9
-5
lines changed
  • packages/@vuepress/core/lib/node/build

1 file changed

+9
-5
lines changed

packages/@vuepress/core/lib/node/build/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const createServerConfig = require('../webpack/createServerConfig')
1111
const { createBundleRenderer } = require('vue-server-renderer')
1212
const { normalizeHeadTag, applyUserWebpackConfig } = require('../util/index')
1313
const { version } = require('../../../package')
14+
const pLimit = require('p-limit')
1415

1516
/**
1617
* Expose Build Process Class.
@@ -91,8 +92,10 @@ module.exports = class Build extends EventEmitter {
9192
// render pages
9293
logger.wait('Rendering static HTML...')
9394

95+
// Use p-limit to throttle number of files done at the same time
96+
const limit = pLimit(RENDER_LIMIT)
9497
const pagePaths = await Promise.all(
95-
this.context.pages.map(page => this.renderPage(page))
98+
this.context.pages.map(page => limit(() => this.renderPage(page)))
9699
)
97100

98101
readline.clearLine(process.stdout, 0)
@@ -145,16 +148,17 @@ module.exports = class Build extends EventEmitter {
145148
version
146149
}
147150

151+
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
152+
const filePath = path.resolve(this.outDir, filename)
148153
try {
149-
const readable = await this.renderer.renderToStream(context)
150-
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
151-
const filePath = path.resolve(this.outDir, filename)
154+
const readable = this.renderer.renderToStream(context)
152155
await fs.ensureDir(path.dirname(filePath))
153-
return pipe(filePath, readable)
156+
await pipe(filePath, readable)
154157
} catch (e) {
155158
console.error(logger.error(chalk.red(`Error rendering ${pagePath}:`), false))
156159
throw e
157160
}
161+
return filePath
158162
}
159163
}
160164

0 commit comments

Comments
 (0)