Javascript Grunt.js任务开发制作咖啡脚本
编辑2:如果使用以下配置(这似乎是自然设置),grunt不会编译任何coffee文件Javascript Grunt.js任务开发制作咖啡脚本,javascript,node.js,coffeescript,gruntjs,Javascript,Node.js,Coffeescript,Gruntjs,编辑2:如果使用以下配置(这似乎是自然设置),grunt不会编译任何coffee文件 coffee: development: compile: expand: true cwd: "<%= srcDirCoffee %>" src: ["**/*.coffee"] dest: "<%= jsOutput %>" ext: ".js" options: sourceMap:true
coffee:
development:
compile:
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
options:
sourceMap:true
并将默认任务更改为
grunt.registerTask('default', ['coffee','less:development'])
它最终起作用了,有人知道为什么会这样吗?它适用于less
,但由于某些原因,它不适用于coffee
这是Grunt任务的my package.json
{
"name": "test",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-less": "~0.9.0",
"grunt-contrib-coffee": "~0.9.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-clean": "~0.5.0"
}
}
将任务选项包装到
文件:[……]
中会把任务搞砸
改为这样做:
compile:
options:
sourceMap: true,
sourceMapDir: 'path/to/maps/' # source map files will be created here
files:
"<%= jsOutput %>": ["**/*.coffee"]
原来我对
compile
选项的含义感到困惑。在grunt.js中,compile
只是一个占位符,它实际上没有任何意义,只是用于文档/演示
以下版本工作正常,没有任何麻烦
coffee:
development:
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
options:
sourceMap:true
production:
expand:true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
咖啡:
发展:
扩展:正确
cwd:“
src:[“***咖啡”]
目的地:“
分机:“.js”
选项:
sourceMap:true
制作:
扩展:正确
cwd:“
src:[“***咖啡”]
目的地:“
分机:“.js”
随着开发
被注释掉,您可以运行咕噜咖啡
,或者这只是默认任务的一部分吗?只是删除文件:[……]
部分似乎起到了作用,但是我很难理解glob\u-to\u-multiple到底做了什么(它本身似乎并没有编译任何咖啡脚本)还请注意,使用编译:
部分不起作用,请参阅我在原始帖子中所做的编辑,我制作的glob\u to\u multiple
是他们给它的名字,因为它接受源代码cwd
中的任何CoffeeScript文件,并将所有文件整合到单独的js文件中,即dest
目录。例如,将一个全局文件转换为多个全局文件。默认情况下,coffee
任务负责编译。在glob\u to\u multiple
中,我们只是添加了额外的选项,以便根据我们的首选项使其工作。@mdedetrich编译部分出了什么问题,是否抛出了错误?更改后,您是否检查压痕是否正确?试着在详细模式下运行它,这样我们就可以看到哪里出了问题:grunt coffee-v
。我想我没有传达我的问题,不是你的代码不工作(它工作),而是在你将任务分为子任务时让它工作,在我的例子中是production
和development
。在执行此操作时,您似乎忽略了compile
选项。我不确定为什么会出现这种情况,但按照编辑1的要求,它工作正常。在这一点上,我只想解释一下为什么会这样
{
"name": "test",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-less": "~0.9.0",
"grunt-contrib-coffee": "~0.9.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-clean": "~0.5.0"
}
}
compile:
options:
sourceMap: true,
sourceMapDir: 'path/to/maps/' # source map files will be created here
files:
"<%= jsOutput %>": ["**/*.coffee"]
compileWithMapsDir: {
options: {
sourceMap: true,
sourceMapDir: 'path/to/maps/' // source map files will be created here
},
files: {
'path/to/result.js': 'path/to/source.coffee'
}
}
coffee:
development:
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
options:
sourceMap:true
production:
expand:true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"