隐藏'正在运行X任务'咕哝着

Hide 'Running X task' in grunt

本文关键字:任务 隐藏 运行      更新时间:2023-09-26

我一直在进行项目设置和部署Gruntfile,但我想隐藏命令行输出,以便执行以下操作:

Running "init" task
Running "prompt:init" (prompt) task
[?] If you continue your project information will be overwritten.
    Continue? (Y/n)

成为

[?] If you continue your project information will be overwritten.
    Continue? (Y/n)

跑步时发出咕噜声。我知道这只是表面上的,但这是我想做的事情,似乎在Grunt的API文档中找不到任何东西来表明这是可以做到的。

这目前不受支持,但由于以下解决方法(来自GitHub上的shama),这是可能的:

grunt.log.header = function () {};

基本上,这会用一个什么都不做的空函数覆盖日志头函数(负责"运行x任务"消息),更重要的是,它什么也不输出。

还有另一种方法:

  • 首先,运行npm install grunt-log-headers来安装grunt日志头
  • 然后将require('grunt-log-headers')(grunt);添加到Gruntfile.js中以启用它
  • 最后,将其添加到任何要隐藏日志头的任务中:

    options: {
        gruntLogHeader: false
    }
    

    示例:

    grunt.initConfig({
        sometask: {
            options: {
                gruntLogHeader: false,
            }
        }
    });
    

事实上,已经为此产生了一个问题。它目前正在开发中,通常在0.5.0版本中可用。