简体   繁体   中英

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

I am working to set up a file minification environment based on Grunt. One step is to load a bunch of script files from the src directory, concatenate them into one file. 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. 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.

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

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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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