Grunt really slow after running and completing "watch" task

601 views Asked by At

For some reason when my terminal hits Running "watch" task Completed in 3.131s at Wed Jun 17 2015 21:00:56... ...) - Waiting... It becomes SO slow, we're talking 1min+ before it populates the rest of data.

terminal response

It might have started when I was trying to sync my db to my elasticsearch server via mongo-connector.

Could it be my mongodb slowing everything down? Any Ideas?

Update Here is my watch in my Grunt.js file:

watch: {
  injectJS: {
    files: [
      '<%= yeoman.client %>/{app,components}/**/*.js',
      '!<%= yeoman.client %>/{app,components}/**/*.spec.js',
      '!<%= yeoman.client %>/{app,components}/**/*.mock.js',
      '!<%= yeoman.client %>/app/app.js'],
    tasks: ['injector:scripts']
  },
  injectCss: {
    files: [
      '<%= yeoman.client %>/{app,components}/**/*.css'
    ],
    tasks: ['injector:css']
  },
  mochaTest: {
    files: ['server/**/*.spec.js'],
    tasks: ['env:test', 'mochaTest']
  },
  jsTest: {
    files: [
      '<%= yeoman.client %>/{app,components}/**/*.spec.js',
      '<%= yeoman.client %>/{app,components}/**/*.mock.js'
    ],
    tasks: ['newer:jshint:all', 'karma']
  },
  gruntfile: {
    files: ['Gruntfile.js']
  },
  livereload: {
    files: [
      '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.css',
      '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.html',
      '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.js',
      '!{.tmp,<%= yeoman.client %>}{app,components}/**/*.spec.js',
      '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.mock.js',
      '<%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}'
    ],
    options: {
      livereload: true
    }
  },
  express: {
    files: [
      'server/**/*.{js,json}'
    ],
    tasks: ['express:dev', 'wait'],
    options: {
      livereload: true,
      nospawn: true //Without this option specified express won't be reloaded
    }
  }
},

I have a client/assets/images/ directory with thousands upon thousands of images. Could that be causing the slowdown?

1

There are 1 answers

3
ThiagoPXP On BEST ANSWER

How many files is this watcher watching!?

A very common misuse is be watching a parent folder where your "node_modules" is a child folder. Therefore, depending on how many node modules you have in use, this watcher might be watching hundreds of thousands of js files...

Key points

1) Make sure your watcher is not watching "node_modules" folder.

2) Use file filters wherever you can to watch only files you care will be watched. The example below only watches for .less files.

// example of watcher for .less files only

watch('../Content', filter(/\.less$/, function (filename) {
    console.log('file changed: ', filename);
}));