I have several files named:
and they are all compiled into one jquery.js file in my output directory. 
Although I guess this behavior might be nice in some cases, I would like to have them to compile into different files like jquery.a.b.js, jquery.a.c.js and so on. How can I tell grunt-contrib-coffeescript to do so?
My Gruntfile.js looks like this:
module.exports = function (grunt) {
    grunt.initConfig({
        coffee: {
          dist: {
            files: [{
              expand: true,
              flatten: true,
              cwd: 'app/webroot/coffee',
              src: ['{,*/}*.coffee'],
              dest: 'app/webroot/js',
              ext: '.js'
            }]
          }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-coffee');
};
Thanks for your help!
The problem lies on the filenames having multiple dots.
If it was jquery-a-b.coffee, jquery-a-c.coffee etc, you would have seen the expected output.
It is a known issue (extension is after last period only) and grunt developers made this on purpose.
Here is a quote from one of them:
There's two ways ext could work; it could consider everything after the first dot the extension, or everything after the last dot the extension. We chose the former because the use-case is more common (we encounter .min.js files all the time). That being said, you can use the rename option to specify a function that will use whatever custom naming logic you need.
So, the only workaround for now is to remove ext and use rename like this:
coffee: {
  dist: {
    files: [{
      expand: true,
      cwd: 'app/webroot/coffee',
      src: ['{,*/}*.coffee'],
      dest: 'app/webroot/js',
      rename: function(dest, src) {
        return dest + '/' + src.replace(/\.coffee$/, '.js');
      }
    }]
  }
}
Update as of Grunt 0.4.3:
You can now use the extDot option along with ext
ext: '.js',
extDot: 'last'
This works so you don't have to add the files by hand in your gruntFile:
coffee: {
    glob_to_multiple: {
    expand: true,
    flatten: true,
    cwd: 'app/webroot/coffee/',
    src: ['*.coffee'],
    dest: 'app/webroot/',
    ext: '.js'
    }
},
See https://github.com/gruntjs/grunt-contrib-coffee#usage-examples for some sample usages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With