diff --git a/packages/@vuepress/core/lib/node/dev/index.js b/packages/@vuepress/core/lib/node/dev/index.js index 3087a52007..d8d1cdbb35 100644 --- a/packages/@vuepress/core/lib/node/dev/index.js +++ b/packages/@vuepress/core/lib/node/dev/index.js @@ -176,7 +176,8 @@ module.exports = class DevProcess extends EventEmitter { .use(DevLogPlugin, [{ port: this.port, displayHost: this.displayHost, - publicPath: this.context.base + publicPath: this.context.base, + clearScreen: this.context.options.clearScreen }]) config = config.toConfig() diff --git a/packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js b/packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js index b51927e677..fd563125ca 100644 --- a/packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js +++ b/packages/@vuepress/core/lib/node/webpack/DevLogPlugin.js @@ -17,10 +17,13 @@ module.exports = class DevLogPlugin { apply (compiler) { let isFirst = true + const { displayHost, port, publicPath, clearScreen: shouldClearScreen = true } = this.options + compiler.hooks.done.tap('vuepress-log', stats => { - clearScreen() + if (shouldClearScreen) { + clearScreen() + } - const { displayHost, port, publicPath } = this.options const time = new Date().toTimeString().match(/^[\d:]+/)[0] const displayUrl = `http://${displayHost}:${port}${publicPath}` @@ -40,7 +43,9 @@ module.exports = class DevLogPlugin { logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress dev')} for the first time.`) } }) - compiler.hooks.invalid.tap('vuepress-log', clearScreen) + if (shouldClearScreen) { + compiler.hooks.invalid.tap('vuepress-log', clearScreen) + } } } diff --git a/packages/docs/docs/api/cli.md b/packages/docs/docs/api/cli.md index 8841bc2c42..d9d6b13a5b 100644 --- a/packages/docs/docs/api/cli.md +++ b/packages/docs/docs/api/cli.md @@ -17,7 +17,7 @@ See [port](../config/README.md#port). See [temp](../config/README.md#temp). ### -c, --cache [cache] -### -no--cache [cache] +### -no--cache See [cache](../config/README.md#cache). ### --debug @@ -36,6 +36,9 @@ See [host](../config/README.md#host). ### --open Open browser when ready. +### --no-clear-screen +do not clear screen when dev server is ready. + ## eject Copy the default theme into `.vuepress/theme` for customization. diff --git a/packages/docs/docs/zh/api/cli.md b/packages/docs/docs/zh/api/cli.md index 1355aa4812..f7f2436dce 100644 --- a/packages/docs/docs/zh/api/cli.md +++ b/packages/docs/docs/zh/api/cli.md @@ -36,6 +36,9 @@ vuepress targetDir [options] ### --open 当服务端准备就绪时自动打开浏览器。 +### --no-clear-screen +当 dev server 就绪时不清除屏幕。 + ## eject 将默认主题复制到 `.vuepress/theme` 目录,以供自定义。 diff --git a/packages/vuepress/lib/registerCoreCommands.js b/packages/vuepress/lib/registerCoreCommands.js index 8f9c54ba47..edca5b2195 100644 --- a/packages/vuepress/lib/registerCoreCommands.js +++ b/packages/vuepress/lib/registerCoreCommands.js @@ -20,6 +20,7 @@ module.exports = function (cli, options) { .option('-c, --cache [cache]', 'set the directory of cache') .option('--host ', 'use specified host (default: 0.0.0.0)') .option('--no-cache', 'clean the cache before build') + .option('--no-clear-screen', 'do not clear screen when dev server is ready') .option('--debug', 'start development server in debug mode') .option('--silent', 'start development server in silent mode') .option('--open', 'open browser when ready')