Question

I used grunt-contrib-concat alot and wondered why some files were not concatenated. I found out it was a small typo. Anyway, I've got a lot of different files with different destinations.

grunt.initConfig({
  concat: {
    js: {
      files: [
        {
          src: ["file1.js"],
          dest: "some/dir/fileXY.js"
        },
        {
          src: ["x/file2.js"],
          dest: "some/other/dir/fileAB.js"
        },

        // and so on, and on
      ]
    }
  }
}

Now as per the docs I have to set nonull: true in the object literal itself, to get some warnings if the file does not exist. Is there a way to set it by default so that I don't have to touch every single one of them?

I tried it with the options object, but no luck so far.

Was it helpful?

Solution

Grunt allow you to get & set any configuration property.

Put it below grunt.initConfig:

  var files = grunt.config.get('concat.js.files').map(function(prop){ 
    prop.nonull = true;
    return prop;
  });

  grunt.config.set('concat.js.files',files);

Another way is to create the object and then pass it to initConfig:

files = [
  {
    src: ['a.js'],
    dest: 'b.js'
  }, {
    src: ['c.js'],
    dest: 'd.js'
  }
];

files = files.map(function(prop) { 
  prop.nonull = true;
  return prop;
});

grunt.initConfig({
  concat: {
    js: { files: files}
  }
});  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top