我是 Grunt 的新手,到目前为止我非常喜欢它。我希望 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 只编译已更改的文件?