Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Grunt任务在应用程序中很慢_Ruby On Rails_Angularjs_Gruntjs_Yeoman - Fatal编程技术网

Ruby on rails Grunt任务在应用程序中很慢

Ruby on rails Grunt任务在应用程序中很慢,ruby-on-rails,angularjs,gruntjs,yeoman,Ruby On Rails,Angularjs,Gruntjs,Yeoman,我与yeoman一起完成了一个angular项目,与rails api后端进行了交流 除了咕噜声任务非常慢之外,一切都正常 当我运行grunt服务器--verbose时: Execution Time (2014-01-15 13:37:55 UTC) loading tasks 14.3s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 26% server 1ms 0% preprocess:multifile 11ms 0% clea

我与yeoman一起完成了一个angular项目,与rails api后端进行了交流

除了咕噜声任务非常慢之外,一切都正常

当我运行
grunt服务器--verbose
时:

Execution Time (2014-01-15 13:37:55 UTC)
loading tasks         14.3s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 26%
server                  1ms  0%
preprocess:multifile   11ms  0%
clean:server           13ms  0%
concurrent:server     34.3s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 63%
autoprefixer            1ms  0%
autoprefixer:dist     369ms  ▇ 1%
connect:livereload     17ms  0%
watch                  5.8s  ▇▇▇▇▇▇▇▇▇ 11%
Total 54.8s
我的一些Gruntfile:

'use strict';
module.exports = function (grunt) {
  require('time-grunt')(grunt);
  require('load-grunt-tasks')(grunt);
  require('time-grunt')(grunt);

  grunt.initConfig({
    ...
  });

grunt.loadNpmTasks('grunt-preprocess');

  grunt.registerTask('server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'preprocess:multifile',
      'clean:server',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  });

  grunt.registerTask('test', [
    'clean:server',
    'concurrent:test',
    'autoprefixer',
    'connect:test'
    //'karma'
  ]);

  grunt.registerTask('build', [
    'preprocess:multifile',
    'clean:dist',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'copy:dist',
    'cdnify',
    'ngmin',
    'cssmin',
    'uglify',
    'rev',
    'usemin'
  ]);

  grunt.registerTask('default', [
    'jshint',
    'test',
    'build'
  ]);

};
项目规模:

vagrant@vm ~code/myapp/app/scripts
$> find -name "*.js" | xargs cat | wc -l
10209
我在MacOS 10.8上运行,带有i7处理器、16GB ram、SSD。。。花这么长时间是正常的吗?是什么使得grunt任务(尤其是“加载任务”)如此缓慢

注意:我被ssh固定在一台流浪机器中,从那里运行grunt命令。如果在本机系统上运行grunt命令,速度会快得多(
加载任务
需要1.6秒,而不是14.3秒)


因此,共享文件系统可能是一个问题。但是为什么…

我在一个流浪的虚拟盒子里用咕噜。(ubuntu 12.04)。我的本机文件位于我的主机(OSx)上。因为grunt任务是io密集型任务,并且它们通过文件共享运行,这使得它们非常慢

这可以通过将nfs添加到Vagrant()来改进。这将使Vagrant与nfs共享文件,而不是默认的Vagrant文件共享。会快一点,但不会太多

作为比较,在我的机器上:

用于运行子任务
加载grunt任务

  • 本机:1.2秒
  • 使用nfs:4s
  • 流浪者文件共享:16s

如果只有一个特定的任务需要花费大量的时间,那么这个特定的任务可能就是问题所在。要进行故障排除,请使用time grunt:。

我在Vagrant和Yeomans角度发生器上遇到了完全相同的问题。运行
grunt-service
后,编译sass、重启服务器等花费了将近30秒的时间

我已经使用了NFS,但速度仍然很慢。然后我试了一下,刚好赶上了咕噜加载器。我用jit grunt替换了load grunt任务,现在一切都快多了

下面是一篇关于JIT Grunt的好文章:

我也遇到了一些问题,并发现:

nospawn: true

是最快的选择。我从20秒到1秒去了concat、minify和uglify JS。

我对约曼的ngbp发生器和Vagrant也有同样的问题。即使使用nfs,对模板的简单更改也需要大约30秒才能在浏览器中看到

使用使时间缩短到10秒。使用spawn:false后,即使在第一次加载时没有减少,更改也用了不到1秒(0.086秒)的时间传播到浏览器!(是的!)

我对
grunfile.js所做的更改:

  • 我对所有的grunt.loadnpmtask都进行了注释,但对grunt.loadnpmtask('grunt-contrib-watch')进行了注释[这是因为ngbp稍后对任务进行了重命名]
  • 我添加了require(“jit-grunt”)(grunt);在grunt.loadNpmTasks之后(“grunt-contrib-watch”)
  • 我将spawn:false添加到delta:{options:{livereload:true,spawn:false}…}

  • 我也有同样的问题。似乎imagemin需要花费很长时间(
    grunt-service--verbose--debug
    公开了这一点)。你想出解决办法了吗?这个。在我的例子中,我运行了一个browserify watch任务,需要7秒钟才能重新编译更改。在watch:browserify的选项部分添加了这个(嗯,“spawn:false”)之后,它下降到了1秒。谢谢@pinouchon。这正是我遇到的问题,而你的解决方案帮助了我。升级。更改此设置后,我将一个小文件的时间从34秒改为259ms。。。。那太疯狂了。