简体   繁体   English

将Grunt任务写入控制台

[英]Write Grunt task to console

This is relevant to any Grunt task which has a source file and a destination (output file). 这与具有源文件和目标(输出文件)的任何Grunt任务有关。

When I run grunt in my command line, I don't want Grunt to write anything to file, I just want to view (return) the output to my console, be it Bash, CMD or any CLI. 当我在命令行中运行grunt时,我不希望Grunt将任何内容写入文件,我只想查看(返回)输出到控制台,无论是Bash,CMD还是任何CLI。

Lets take uglify for example. 让我们以丑陋为例。

module.exports = function(grunt) {

grunt.initConfig({
    uglify: {
          options: {
            mangle: true,
            sourceMap: true,
          },
          build: {
            src: 'js/foo.js',
            dest: 'js/foo.min.js' <-- Don't need this.
          }
    }
});

grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.registerTask('default', ['uglify']);
};

Instead of Done, without errors , when successful, I want to view the uglifed code in the console. 成功完成后,我想在控制台中查看uglifed代码Done, without errors不是Done, without errorsDone, without errors

For context, I need this for a command line application which won't need anything written to disk. 对于上下文,我对于不需要将任何内容写入磁盘的命令行应用程序都需要这样做。 I just need to use the output on the fly (I'm trying to avoid writing to file and re-reading from the CLI). 我只需要即时使用输出(我试图避免写入文件并从CLI重新读取)。

You could write directly to /dev/stdout ( not on windows tough ): 您可以直接写到/dev/stdout (不是在Windows hard上):

build: {
    src: 'js/foo.js',
    dest: '/dev/stdout'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM