0
/assets/src/coffee
等(./child/paths
等)中的許多咖啡源文件,我想輸出它們到assets/js/
和assets/js/child/paths
。使用grunt,是否有可能編譯並輸出一個更改的文件到不同的目錄?
它看起來像我已經接近,但它不工作。使用grunt-contrib-coffee
和grunt-contrib-watch
。
grunt.initConfig
watch:
coffee:
files: '<%= coffee.src %>',
tasks: 'coffee:dev'
options:
nospawn: true
coffee:
src: 'assets/src/coffee/**/*.coffee'
dev:
options:
sourceMap: true
files: [
expand: true
cwd: "assets/"
src: "/src/coffee/**/*.coffee"
dest: "../js/"
ext: ".js"
]
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks 'grunt-contrib-watch'
# Default task.
grunt.registerTask "default", "watch"
grunt.event.on('watch', (action, filepath) ->
(grunt.log.writeln('\n'+ filepath + ' has ' + action))
dest = "#{path.dirname(filepath.replace("src/coffee", "js"))}"
grunt.config(['coffee', 'dev', 'files', 'src'], [filepath])
grunt.config(['coffee', 'dev', 'files', 'dest'], [dest])
(grunt.log.writeln("src: #{grunt.config(['coffee', 'dev', 'files', 'src'])}"))
(grunt.log.writeln("dest: #{grunt.config(['coffee', 'dev', 'files', 'dest'])}"))
)
好了,所以,它的輸出看起來像:
assets/src/coffee/projAlpha/dl.coffee has changed
src: assets/src/coffee/projAlpha/dl.coffee
dest: assets/js/projAlpha/dl.coffee
但文件實際上是在結束了:assets/src/coffee/projAlpha/dl.coffee
......和它的咖啡腳本。它應該在assets/js/projAlpha/dl.js
。
我已經得到了grunt咖啡工具,立即編譯所有文件,並把它們放在正確的地方。我寧願他們每次都編譯一個,因爲我現在有幾個文件,並且一直在增加更多。
嗯不完全是:「警告:EACCES,權限被拒絕'/ dev/fd/10'」 – jcollum 2013-04-25 15:50:59
我的不好,「cwd」應該有一個尾部的斜線。我已經把它作爲「src」中的主要斜線。 – 2013-04-25 16:07:46
嗯,他們沒有在代碼中使用path.join?我應該去看看...... – jcollum 2013-04-25 16:20:26