File tree 4 files changed +21
-3
lines changed
@vuepress/core/lib/node/build
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 {
20
20
constructor ( context ) {
21
21
super ( )
22
22
this . context = context
23
+ this . maxConcurrency = this . context . options . maxConcurrency
23
24
this . outDir = this . context . outDir
24
25
}
25
26
@@ -91,9 +92,18 @@ module.exports = class Build extends EventEmitter {
91
92
// render pages
92
93
logger . wait ( 'Rendering static HTML...' )
93
94
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
+ }
97
107
98
108
readline . clearLine ( process . stdout , 0 )
99
109
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.
54
54
55
55
Start development server in silent mode.
56
56
57
+ #### --max-concurrency
58
+
59
+ Set the max concurrency for rendering pages, to prevent OOM when rendering massive docs.
60
+
57
61
### dev
58
62
59
63
Start 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]
29
29
### --silent
30
30
以安静模式启动开发服务器。
31
31
32
+ ### --max-concurrency
33
+ 设置渲染文档的最大并发量,当渲染大量文档,可能造成内存溢出时使用
34
+
32
35
## dev
33
36
34
37
启动一个开发服务器。来自 ` vuepress build ` 的所有选项都可用。除此以外,还有几个专门针对 dev 的选项:
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ module.exports = function (cli, options) {
51
51
. option ( '--no-cache' , 'clean the cache before build' )
52
52
. option ( '--debug' , 'build in development mode for debugging' )
53
53
. option ( '--silent' , 'build static site in silent mode' )
54
+ . option ( '--max-concurrency' , 'set the max docs concurrently processed when build static site' )
54
55
. action ( ( sourceDir = '.' , commandOptions ) => {
55
56
const { debug, silent } = commandOptions
56
57
You can’t perform that action at this time.
0 commit comments