Coffeescript grunt contrib咖啡一对一编译
我有几个文件名为:Coffeescript grunt contrib咖啡一对一编译,coffeescript,gruntjs,Coffeescript,Gruntjs,我有几个文件名为: jquery.a.b.咖啡 jquery.a.c.咖啡 jquery.a.d.咖啡 它们都被编译到我的输出目录中的一个jquery.js文件中 虽然我认为这种行为在某些情况下可能很好,但我希望将它们编译成不同的文件,如jquery.a.b.js,jquery.a.c.js等等。我怎样才能告诉grunt contrib coffeescript这样做 我的GrunFile.js如下所示: module.exports = function (grunt) { gru
- jquery.a.b.咖啡
- jquery.a.c.咖啡
- jquery.a.d.咖啡
jquery.js
文件中
虽然我认为这种行为在某些情况下可能很好,但我希望将它们编译成不同的文件,如jquery.a.b.js
,jquery.a.c.js
等等。我怎样才能告诉grunt contrib coffeescript这样做
我的GrunFile.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');
};
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');
}
}]
}
}
谢谢你的帮助 这样做可以使您不必在GrunFile中手动添加文件:
coffee: {
glob_to_multiple: {
expand: true,
flatten: true,
cwd: 'app/webroot/coffee/',
src: ['*.coffee'],
dest: 'app/webroot/',
ext: '.js'
}
},
有关一些示例用法,请参见。问题在于文件名有多个点。
如果是jquery-a-b.coffee、jquery-a-c.coffee等,您就会看到预期的输出 这是一个已知的扩展(仅在最后一期之后),grunt开发人员故意这样做。
以下是其中一人的一句话: ext有两种工作方式;它可以考虑一切之后 第一个点表示扩展,或最后一个点之后的所有内容表示扩展 分机。我们选择前者是因为用例更常见(我们 始终遇到.min.js文件)。也就是说,你可以使用 重命名选项指定将使用任何自定义项的函数 您需要的命名逻辑 因此,目前唯一的解决办法是删除
ext
,然后像这样使用rename
:
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');
};
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');
}
}]
}
}
从Grunt 0.4.3开始更新:
现在,您可以与
ext一起使用
ext: '.js',
extDot: 'last'
没有其他选项吗,这将需要很多文件好的,这个解决方案不编译任何东西。我已经更改了数据以满足您的需要,当您执行coffee任务时返回什么?(使用grunt coffee
)非常感谢,但问题仍然存在:$grunt coffee运行“coffee:glob_to_multiple”(咖啡)任务文件app/webroot/jquery.js。为什么需要“flatte:true”?@KrisKhaira我相信在这种情况下没有必要使用flatte
选项,所以我从答案中删除了它。谢谢你的注意。