简体   繁体   English

为什么grunt-contrib-concat不应用我的进程回调?

[英]Why does grunt-contrib-concat not apply my process callback?

I am working to set up a file minification environment based on Grunt. 我正在努力建立一个基于Grunt的文件缩小环境。 One step is to load a bunch of script files from the src directory, concatenate them into one file. 第一步是从src目录中加载一堆脚本文件,并将它们串联到一个文件中。 When concatenating the source files i want concat to process the loaded source in that it trims the loaded string to get rid of leading and trailing blank lines. 在连接源文件时,我希望concat处理加载的源,因为它会修剪加载的字符串以摆脱开头和结尾的空行。 However, this seems not to work, as the returned function value does not appear in the file created. 但是,这似乎不起作用,因为返回的函数值未出现在创建的文件中。 Here's the responsible code block of my gruntfile. 这是我的gruntfile的负责代码块。

concat : {
   js : {
      options : {
         separator : '',
         stripBanners : {
            block : true,
            line : true
         }
      },
      src : ['<%= srcDir %>/js/*.js'],
      dest : '<%= buildDir %>/<%= pkg.name %>.concat.js',
      nonull: true,
      process : function (src, filepath) {
         return 'TEST'
      }
   }
}

Why does the returned value never appear in my target file and why does it contain the contents of the loaded source files concatenated? 为什么返回的值永远不会出现在目标文件中,为什么它包含级联的已加载源文件的内容?

process should be defined in the options object according to https://github.com/gruntjs/grunt-contrib-concat#custom-process-function 应根据https://github.com/gruntjs/grunt-contrib-concat#custom-process-functionoptions对象中定义process

try 尝试

concat : {
    js : {
        options : {
            separator : '',
            stripBanners : {
                block : true,
                line : true
            },
            process : function (src, filepath) {
                return 'TEST'
            }
        },
        src : ['<%= srcDir %>/js/*.js'],
        dest : '<%= buildDir %>/<%= pkg.name %>.concat.js',
        nonull: true
    }
}

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

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