File tree Expand file tree Collapse file tree 4 files changed +21
-3
lines changed
@vuepress/core/lib/node/build Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ module.exports = class Build extends EventEmitter {
2020 constructor ( context ) {
2121 super ( )
2222 this . context = context
23+ this . maxConcurrency = this . context . options . maxConcurrency
2324 this . outDir = this . context . outDir
2425 }
2526
@@ -91,9 +92,18 @@ module.exports = class Build extends EventEmitter {
9192 // render pages
9293 logger . wait ( 'Rendering static HTML...' )
9394
94- const pagePaths = await Promise . all (
95- this . context . pages . map ( page => this . renderPage ( page ) )
96- )
95+ // If maxConcurrency is set, instead of rendering all pages concurrently,
96+ // build task would render pages by smaller group to prevent OOM.
97+ if ( this . maxConcurrency ) logger . info ( `max concurrency set: ${ this . maxConcurrency } ` )
98+ const pagePaths = [ ]
99+ const maxConcurrency = this . maxConcurrency || 100000
100+ for ( let i = 0 ; i < this . context . pages . length ; i += maxConcurrency ) {
101+ const segmentPaths = await Promise . all (
102+ this . context . pages . slice ( i , i + maxConcurrency )
103+ . map ( page => this . renderPage ( page ) )
104+ )
105+ pagePaths . push ( ...segmentPaths )
106+ }
97107
98108 readline . clearLine ( process . stdout , 0 )
99109 readline . cursorTo ( process . stdout , 0 )
Original file line number Diff line number Diff line change @@ -54,6 +54,10 @@ Start development server in debug mode.
5454
5555Start development server in silent mode.
5656
57+ #### --max-concurrency
58+
59+ Set the max concurrency for rendering pages, to prevent OOM when rendering massive docs.
60+
5761### dev
5862
5963Start a development server. All options from ` vuepress build ` are available. And there are several options specifically for dev:
Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ vuepress <command> targetDir [options]
2929### --silent
3030以安静模式启动开发服务器。
3131
32+ ### --max-concurrency
33+ 设置渲染文档的最大并发量,当渲染大量文档,可能造成内存溢出时使用
34+
3235## dev
3336
3437启动一个开发服务器。来自 ` vuepress build ` 的所有选项都可用。除此以外,还有几个专门针对 dev 的选项:
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ module.exports = function (cli, options) {
5151 . option ( '--no-cache' , 'clean the cache before build' )
5252 . option ( '--debug' , 'build in development mode for debugging' )
5353 . option ( '--silent' , 'build static site in silent mode' )
54+ . option ( '--max-concurrency' , 'set the max docs concurrently processed when build static site' )
5455 . action ( ( sourceDir = '.' , commandOptions ) => {
5556 const { debug, silent } = commandOptions
5657
You can’t perform that action at this time.
0 commit comments