【发布时间】:2014-02-27 16:29:31
【问题描述】:
编辑 2:如果使用以下配置(这似乎是自然设置),grunt 不会编译任何咖啡文件
coffee:
development:
compile:
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
options:
sourceMap:true
使用 -v 标志运行时,Grunt 会输出以下内容 https://gist.github.com/mdedetrich/0ecccb50ddb2fd56dc35
编辑:相关部分现在看起来像这样,并且似乎可以正常工作
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"
但是,它为什么只能以这种方式工作(以及为什么需要删除编译部分才能使其工作)有点令人困惑
原始问题:
我目前正在设置一个 Gruntjs 任务,看起来像这样
module.exports = (grunt) ->
grunt.initConfig(
pkg: grunt.file.readJSON("package.json")
srcDir: "./src/main"
srcDirLess: "<%= srcDir %>/less"
srcDirCoffee: "<%= srcDir %>/coffee"
scalaVersion: "scala-2.10" #This is the scala version we are using
resourceManaged: "./target/<%= scalaVersion %>/resource_managed/main"
cssOutput: "<%= resourceManaged %>/css"
jsOutput: "<%= resourceManaged %>/js"
cssRequestPath: "/css"
jsRequestPath: "/js"
less:
development:
options:
paths: ["<%= srcDirLess %>"]
# sourceMap:true
# sourceMapFilename: "<%= cssOutput %>/index.css.map"
# sourceMapRootpath: "<%= srcDirLess %>"
# sourceMapURL: "<%= cssRequestPath %>/index.css.map"
files:
"<%= cssOutput %>/index.css" : "<%= srcDirLess %>/index.less"
production:
options:
paths: ['<%= srcDirLess %>']
cleancss:true
files:
"<%= cssOutput %>/index.css" : "<%= srcDirLess %>/index.less"
coffee:
development:
compile:
files: [
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
]
# options:
# sourceMap:true
production:
compile:
files: [
expand:true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
]
requirejs:
production:
compile:
options:
baseUrl: "<%= jsOutput %>"
mainConfigFile: "<%= jsOutput %>/main"
watch:
coffee:
files: "<%= srcDirCoffee %>/**/*.coffee"
tasks: ["coffee:development"]
less:
files: "<%= srcDirLess %>/**/*.less"
tasks: ["less:development"]
clean: ["<%= cssOutput %>","<%= jsOutput %>"]
)
grunt.loadNpmTasks('grunt-contrib-less')
grunt.loadNpmTasks('grunt-contrib-coffee')
grunt.loadNpmTasks('grunt-contrib-requirejs')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.registerTask('default', ['coffee:development','less:development'])
grunt.registerTask('production',['less:production','coffee:production','requirejs:production'])
不幸的是,由于某种原因,defaultcoffee 任务无法正常工作(即它实际上并没有运行该任务)。如果我取出咖啡任务中的开发/生产部分,即
coffee:
# development:
compile:
files: [
expand: true
cwd: "<%= srcDirCoffee %>"
src: ["**/*.coffee"]
dest: "<%= jsOutput %>"
ext: ".js"
]
并将默认任务更改为
grunt.registerTask('default', ['coffee','less:development'])
它最终工作了,有人知道为什么会这样吗?它适用于less,但由于某种原因它不适用于coffee
这是我用于 Grunt 任务的 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"
}
}
【问题讨论】:
-
development被注释掉后,您可以运行grunt coffee,还是仅作为默认任务的一部分工作?
标签: javascript node.js coffeescript gruntjs