即使spawn = false,grunt-contrib-watch也很慢 [英] grunt-contrib-watch slow even with spawn = false

查看:167
本文介绍了即使spawn = false,grunt-contrib-watch也很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了grunt-contrib-watch任务,以便每次保存src目录中的一个文件时将文件列表复制到dist目录。不幸的是,完成这项任务需要7到9秒。



我听说过 spawn选项用于grunt-contrib-watch 。使用load-grunt-tasks从单独的JSON文件加载每个任务的配置,我改变了我的watch.json,使它看起来像这样:

  {
service:{
files:[
src / *。php

tasks): [
copy:service
],
options:{
spawn:false,
livereload:true



$ / code $ / pre

...但将其设置为false似乎没有改变任何东西:它仍然需要7到9秒才能运行。我安装了time-grunt来监视任务计时,这是我在保存文件时得到的结果:



保存文件时,我得到以下输出:

 等待... 
>>文件src\myfile.php已更改。

运行copy:service(复制)任务
创建7个目录,复制120个文件

完成,没有错误。


执行时间(2015-06-04 11:38:23 UTC)
加载任务333ms████████████████ ██40%
副本:服务490ms██████████████████████████60%
总计823ms

完成时间:星期四04.10 15:05:10 GMT + 0200(W. Europe Daylight Time)

所以看起来这个任务本身花费的时间不到一秒,这意味着Grunt本身需要6秒才能加载?这似乎很高。我在Windows 7上,我听说在Windows上可能会有一些性能问题。

解决方案

同样的问题在这里,在改变并执行任务后,所有模块都被重新加载。



但是我发现github
https://github.com/steida/grunt-este-watch


官方grunt-contrib-watch有什么问题?



由于历史原因,它使用组合fs.fileWatch和fs.watch,因此速度慢并且有问题。从节点0.9.2+开始,fs.watch就可以了。



该怎么办?




  1. 安装grunt-este-watch

      npm install grunt-este-watch --save-dev 


  2. 更改contrib手表

      grunt.loadNpmTasks( '咕噜-的contrib手表'); 

    到手表

      grunt.loadNpmTasks( '咕噜-Este的手表'); 


  3. 更改任务

    <$ p $ watch:{
    javascript:{
    files:'src / js / ** / *',
    tasks:['uglify']
    }
    }

      esteWatch:{
    options:{
    dirs:['../src/**/*']
    },
    ' js':function(filepath){return'uglify'}
    }



I have set up the grunt-contrib-watch task to copy a list of files to a "dist" directory every time I save one of the files of the "src" directory. Unfortunately it takes 7 to 9 seconds to accomplish this task.

I have heard about the "spawn" option for grunt-contrib-watch. Using load-grunt-tasks to load the config of each task from a separate JSON file, I changed my watch.json so that it looks like this :

{
    "service": {
        "files": [
            "src/*.php"
        ],
        "tasks": [
            "copy:service"
        ],
        "options": {
            "spawn": "false",
            "livereload": "true"
        }
    }
}

...but setting it to false doesn't seems to change anything : it still takes 7 to 9 seconds to run. I installed time-grunt to monitor the task timing, here is what I got when saving a file :

When saving a file, I got the following output :

Waiting...
>> File "src\myfile.php" changed.

Running "copy:service" (copy) task
Created 7 directories, copied 120 files

Done, without errors.


Execution Time (2015-06-04 11:38:23 UTC)
loading tasks  333ms  ██████████████████ 40%
copy:service   490ms  ██████████████████████████ 60%
Total 823ms

Completed in 7.105s at Thu Jun 04 2015 13:38:24 GMT+0200 (W. Europe Daylight Time)

So it looks like the task in itself took less than a second, meaning that Grunt itself would take 6 seconds to load ? That seems pretty high. I'm on Windows 7, I've heard that on Windows there could be some performance issues.

解决方案

Same problem here, after changed and execute task all modules was reload.

But i found a very good solution on github (https://github.com/steida/grunt-este-watch)

What's wrong with official grunt-contrib-watch?

It's slow and buggy, because it uses combination fs.fileWatch and fs.watch, for historical reason. From Node 0.9.2+, fs.watch is ok.

What to do?

  1. install grunt-este-watch

    npm install grunt-este-watch --save-dev
    

  2. change contrib watch

    grunt.loadNpmTasks('grunt-contrib-watch');
    

    to este watch

    grunt.loadNpmTasks('grunt-este-watch');
    

  3. change task

    watch: {
      javascript: {
          files: 'src/js/**/*',
          tasks: ['uglify']
      }
    }
    

    to

    esteWatch: {
       options: {
          dirs: ['../src/**/*']
       },
       'js': function(filepath) { return 'uglify' }
    }
    

这篇关于即使spawn = false,grunt-contrib-watch也很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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