Skip to content

Commit e5f51de

Browse files
committed
feat($cli): --no-clear-screen flag (close: #1421)
1 parent d1ea2da commit e5f51de

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ module.exports = class DevProcess extends EventEmitter {
176176
.use(DevLogPlugin, [{
177177
port: this.port,
178178
displayHost: this.displayHost,
179-
publicPath: this.context.base
179+
publicPath: this.context.base,
180+
clearScreen: this.context.options.clearScreen
180181
}])
181182

182183
config = config.toConfig()

packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ module.exports = class DevLogPlugin {
1717

1818
apply (compiler) {
1919
let isFirst = true
20+
const { displayHost, port, publicPath, clearScreen: shouldClearScreen = true } = this.options
21+
2022
compiler.hooks.done.tap('vuepress-log', stats => {
21-
clearScreen()
23+
if (shouldClearScreen) {
24+
clearScreen()
25+
}
2226

23-
const { displayHost, port, publicPath } = this.options
2427
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
2528
const displayUrl = `http://${displayHost}:${port}${publicPath}`
2629

@@ -40,7 +43,9 @@ module.exports = class DevLogPlugin {
4043
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress dev')} for the first time.`)
4144
}
4245
})
43-
compiler.hooks.invalid.tap('vuepress-log', clearScreen)
46+
if (shouldClearScreen) {
47+
compiler.hooks.invalid.tap('vuepress-log', clearScreen)
48+
}
4449
}
4550
}
4651

packages/docs/docs/api/cli.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See [port](../config/README.md#port).
1717
See [temp](../config/README.md#temp).
1818

1919
### -c, --cache [cache]
20-
### -no--cache [cache]
20+
### -no--cache
2121
See [cache](../config/README.md#cache).
2222

2323
### --debug
@@ -36,6 +36,9 @@ See [host](../config/README.md#host).
3636
### --open
3737
Open browser when ready.
3838

39+
### --no-clear-screen
40+
do not clear screen when dev server is ready.
41+
3942
## eject
4043

4144
Copy the default theme into `.vuepress/theme` for customization.

packages/docs/docs/zh/api/cli.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ vuepress <command> targetDir [options]
3636
### --open
3737
当服务端准备就绪时自动打开浏览器。
3838

39+
### --no-clear-screen
40+
当 dev server 就绪时不清除屏幕。
41+
3942
## eject
4043

4144
将默认主题复制到 `.vuepress/theme` 目录,以供自定义。

packages/vuepress/lib/registerCoreCommands.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = function (cli, options) {
2020
.option('-c, --cache [cache]', 'set the directory of cache')
2121
.option('--host <host>', 'use specified host (default: 0.0.0.0)')
2222
.option('--no-cache', 'clean the cache before build')
23+
.option('--no-clear-screen', 'do not clear screen when dev server is ready')
2324
.option('--debug', 'start development server in debug mode')
2425
.option('--silent', 'start development server in silent mode')
2526
.option('--open', 'open browser when ready')

0 commit comments

Comments
 (0)