Grunt:观看多个文件,只编译改变 [英] Grunt: Watch multiple files, Compile only Changed

查看:194
本文介绍了Grunt:观看多个文件,只编译改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Grunt的新人,到目前为止我非常喜欢。
当运行 grunt watch



时,我希望Grunt仅编译更改的文件我目前有(相关部分)。

注意:assets / javascript / app.coffee和assets / javascript / app.js是目录

 咖啡:
默认值:
expand:true
cwd:assets / javascript / app.coffee
src :[* .coffee]
dest:assets / javascript / app.js
ext:.js

uglify:
dev:
选项:
beautify:true
compress:false
mangle:false
preserveComments:'all'

文件:
js / app.js:assets / javascript / app.js / *。js
js / libs.js:assets / javascript / libs / *。js
$ b b 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
选项:
livereload:true

但我首先编译app.coffee到app.js,所以在我分发我的工作后,不喜欢Coffeescript的人可以以一些合理的方式浏览代码。


$ b $所有这一切的问题是,现在我保存一个Coffeescript文件,我得到太多的步骤(我想):

 >>文件assets / javascript / app.coffee / browse.coffee已更改。 

运行coffee:default(coffee)task
创建文件assets / javascript / app.js / browse.js。
创建文件assets / javascript / app.js / filters.js。

完成,没有错误。
2013年5月28日星期二完成于0.837s 12:30:18 GMT + 0300(EEST) - Waiting ...
OK
>>文件assets / javascript / app.js / browse.js已更改。
>>文件assets / javascript / app.js / filters.js已更改。

运行uglify:dev(uglify)task
创建文件js / app.js。
创建文件js / libs.js。

完成,没有错误。
2013年5月28日星期二于0831s完成12:30:19 GMT + 0300(EEST) - Waiting ...
OK
>文件js / app.js已更改。
>>文件js / libs.js已更改。

2013年5月28日星期二完成时间:0.000s 12:30:19 GMT + 0300(EEST) - Waiting ...

目前我只是设置我的项目,但我会有更多的Coffeescript文件,我不想Coffeescript重新编译所有的文件,在每个文件更改。



此外,libs.js在所有这一切都没有部分,但我想它仍然是编译,因为它也匹配assets / * / .js模式。



有没有办法让Grunt只编译已经更改的文件?










npm install grunt-newer --save-dev



然后在Gruntfile咕噜):

 手表:
coffeescript:
文件:'assets / javascript / * .coffee'
tasks:[newer:coffee]

The Awesome grunt-newer 非常棒!


I'm new to Grunt, and so far I'm enjoying it very much. I want Grunt to compile only the changed files when running grunt watch

In my Grunfile.coffee I currently have (relevant parts).
Note: assets/javascript/app.coffee and assets/javascript/app.js are directories

    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

There is probably a shorter way around, but I'm compiling app.coffee to app.js first, so that after I distribute my work, people who aren't comfortable with Coffeescript can browse the code in somewhat reasonable manner.

The problem with all this is that now that I save a Coffeescript file, I get too many steps ( I think ):

>> 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...

Currently I'm just setting up my project, but I will have a lot more Coffeescript files, and I don't want Coffeescript to recompile all of the files, on each file change.

Furthermore, libs.js has no part in all of this at all, but I guess it is still compiled, because it also matches the "assets/*/.js" pattern.

Is there a way to make Grunt compile only the files that have changed ?

解决方案

I've finally found a real solution! And it's super simple too!

npm install grunt-newer --save-dev

Then in your Gruntfile (after loading the task in grunt):

watch:
    coffeescript:
        files: 'assets/javascript/**/*.coffee'
        tasks: ["newer:coffee"]

And that's it! The Awesome grunt-newer is awesome!

这篇关于Grunt:观看多个文件,只编译改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆