Search code examples
javascriptgruntjsgrunt-contrib-concat

Concat a single file to every file in a directory using grunt


Using Grunt, I want to concat one file to all of the files in a build directory. The purpose of doing so is to append (or potentially prepend) IE specific CSS files to a build CSS file.

To task this:

build/
  file1.css
  file2.css
  file3.css

And create this:

build/
  file1.css
  file1.ie.css
  file2.css
  file2.ie.css
  file3.css
  file3.ie.css

I thought that the expand option might be what I was looking for but I can't figure out how to get it to do what I want.


Solution

  • Try the banner option in grunt-contrib-concat:

    concat: {
      dist: {
        options: {
          banner: '/* IE specific things here */',
        },
        expand: true,
        cwd: 'build/',
        ext: '.ie.css',
        src: ['**/*.css'],
        dest: 'build/',
      },
    },