我刚开始使用Grunt,到目前为止我非常喜欢它。我希望在运行grunt watch
时,只编译已更改的文件。
在我的 Grunfile.coffee 文件中,我目前有以下相关部分。
注意:assets/javascript/app.coffee 和 assets/javascript/app.js 是目录。
coffee:
default:
expand: true
cwd: "assets/javascript/app.coffee"
src: ["*.coffee"]
dest: "assets/javascript/app.js"
ext: ".js"
uglify:
dev:
options:
beautify: true
compress: false
mangle: false
preserveComments: 'all'
files:
"js/app.js": "assets/javascript/app.js/*.js"
"js/libs.js": "assets/javascript/libs/*.js"
watch:
coffeescript:
files: 'assets/javascript/**/*.coffee'
tasks: ["coffee"]
javascript:
files: "assets/**/*.js"
tasks: ["uglify:dev"]
livereload:
files: ["Gruntfile.coffee", "js/*.js", "*.php", "css/*.css", "images/**/*.{png,jpg,jpeg,gif,webp,svg}", "js/*.js", ]
options:
livereload: true
可能有更简短的方法,但我首先将app.coffee编译为app.js,这样在我分发作品后,不熟悉Coffeescript的人可以以比较合理的方式浏览代码。
问题在于现在当我保存Coffeescript文件时,我需要执行太多步骤(我认为):
>> File "assets/javascript/app.coffee/browse.coffee" changed.
Running "coffee:default" (coffee) task
File assets/javascript/app.js/browse.js created.
File assets/javascript/app.js/filters.js created.
Done, without errors.
Completed in 0.837s at Tue May 28 2013 12:30:18 GMT+0300 (EEST) - Waiting...
OK
>> File "assets/javascript/app.js/browse.js" changed.
>> File "assets/javascript/app.js/filters.js" changed.
Running "uglify:dev" (uglify) task
File "js/app.js" created.
File "js/libs.js" created.
Done, without errors.
Completed in 0.831s at Tue May 28 2013 12:30:19 GMT+0300 (EEST) - Waiting...
OK
>> File "js/app.js" changed.
>> File "js/libs.js" changed.
Completed in 0.000s at Tue May 28 2013 12:30:19 GMT+0300 (EEST) - Waiting...
目前我正在设置我的项目,但我将有更多的Coffeescript文件,我不希望Coffeescript在每次文件更改时重新编译所有文件。
此外,libs.js对此毫无作用,但我猜测它仍然会被编译,因为它也符合“assets/*/.js”模式。
有没有办法让Grunt只编译已更改的文件?