grunt-contrib-coffee一对一编译

Dan*_*idt 5 coffeescript gruntjs

我有几个名为的文件:

  • jquery.abcoffee
  • jquery.accoffee
  • jquery.adcoffee

它们都被编译到jquery.js我的输出目录中的一个文件中.

虽然我猜这种行为在某些情况下可能会很好,但我希望让它们编译成不同的文件jquery.a.b.js,jquery.a.c.js等等.我怎么能告诉grunt-contrib-coffeescript呢?

我的Gruntfile.js看起来像这样:

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');

};
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

mut*_*til 10

问题在于具有多个点的文件名.
如果它是jquery-ab.coffee,jquery-ac.coffee等,你会看到预期的输出.

这是一个已知问题(扩展仅在上一个时期之后),而且咕噜咕噜的开发人员故意这样做.
以下是其中一个的引用:

分机有两种方式可以工作; 它可以考虑第一个点后的所有内容,或者最后一个点后的所有内容.我们选择前者是因为用例更常见(我们一直遇到.min.js文件).话虽这么说,您可以使用重命名选项来指定将使用您需要的任何自定义命名逻辑的函数.

所以,现在唯一的解决方法是删除ext和使用rename这样:

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');
      }
    }]
  }
}
Run Code Online (Sandbox Code Playgroud)

更新为步兵0.4.3的:
现在,您可以使用extDot选项一起ext

ext: '.js',
extDot: 'last'
Run Code Online (Sandbox Code Playgroud)

  • @KrisKhaira我认为在这种情况下不需要`flatten`选项,所以我把它从我的答案中删除了.感谢您的注意. (2认同)