gruntjs - Grunt.js watch - node_modules always being watched -


i'm using grunt livereload only. works fine, noticed has high cpu, , when run "--verbose" see it's watching whole "node_modules" folder.

so, made research, , tried ignore this. unfortunately, no success.

my watch part of "gruntfile.js" is:

    // watch stuff ..     watch: {         all: {             files: ['!**/node_modules/**', 'js/**/*.js', 'css/**/*.css', 'index.html'],             options: {                 interval: 5007,                 livereload: true             }         }     }, 

and i'm saying want grunt watch js, css , index.html file. explicitly added code ignoring "node_modules", still says it's watching , cpu goes around 30%. (mac osx)

==================

one thing noticed though:

when make change in "gruntfile.js" - example add 1 more file "files" property of "watch" task - restarts grunt, , in console see start watching files want, , cpu goes below 1%. (i guess it's how should originally.)

what doing wrong?

====================

edit: unfortunately, when change gruntfile , see files want being watched - livereload stuff no longer working.

====================

this article started from: http://thecrumb.com/2014/03/15/using-grunt-for-live-reload/

here package.json file:

{   "name": "grunt-reload",   "version": "1.0.0",   "devdependencies": {         "grunt": "~0.4.3",         "matchdep": "~0.3.0",         "grunt-express": "~1.2.1",         "grunt-contrib-watch": "~0.6.0",         "grunt-open": "~0.2.3"   } } 

and here gruntfile.js:

module.exports = function(grunt) {      require('matchdep')         .filterdev('grunt-*')         .foreach(grunt.loadnpmtasks);      grunt.initconfig({          // web server ..         express: {             all: {                 options: {                     bases: [__dirname],                     port: 8888,                     hostname: 'localhost',                     livereload: true                 }             }         },          // watch stuff ..         watch: {             all: {                 files: ['js/**/*.js', 'css/**/*.css', 'index.html'],                 options: {                     livereload: true                 }             }         },          // automatic opening stuff ..         open: {             all: {                 path: 'http://localhost:8888/index.html'             }         }     });      // create server task ..     grunt.registertask(         'server',         ['express', 'open', 'watch']     );  }; // end of "module.exports" .. 

and start of "grunt server".

edit: after shared gruntfile, problem became more clearer.

in grunt-express config, have set livereload true , bases __dirname, folder gruntfile in ran from.

now, let's @ grunt-express documentation:

bases

type: string|array default: null

the bases (or root) directories static files served. connect.static() generated each entry of bases. when livereload set true (or set specific port number), watch task created (at runtime) watch basepath/**/*.*.

(emphasis mine)

so in grunt-express config, set livereload watch files in basepath, of course includes node_modules.

you have couple of options:

  1. remove other watch task , config grunt-expresses basepath accordingly (just copy other config basically).

  2. keep both of watch tasks , ignore node_modules in other grunt-express -> bases config.

  3. remove bases , handle livereloading in other watch task


where node_modules folder located? if it's on root, can remove node_modules parameter altogether long there aren't matching glob patterns:

// watch stuff .. watch: {     all: {         files: ['js/**/*.js', 'css/**/*.css', 'index.html'],         options: {             interval: 5007,             livereload: true         }     } }, 

now watching: .js-files under js folder, index.html on root , on.

however if have node_modules under js/node_modules, can explicitly ignore folder , files in it:

 files: ['!js/node_modules/**', 'js/**/*.js', 'css/**/*.css', 'index.html'], 

anyway, depending on gruntfiles , node_module-folders location configuration should work fine anyway.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -