grunt-contrib-watch: High CPU usage
Hi, Grunt Watch consumes about 65-70% CPU Resources.
my devDependencies are as follows.
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.9.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-sass": "^0.18.1",
"load-grunt-tasks": "^3.1.0",
"node-bourbon": "^4.2.1-beta1"
}
my gruntfile:
var path = "C:/gdrive/apps/3oak/wp-content/themes/3flooring/";
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Watch ===========
watch: {
// Sass -----
sass: {
files: [
path + 'components/sass/*.{scss,sass}',
path + 'components/sass/styles/*.{scss,sass}',
path + 'components/sass/styles/custom/*.{scss,sass}',
path + 'components/sass/styles/custom/**/*.{scss,sass}'
],
tasks: ['sass']
},
// Reload -
livereload: {
files: [
path + '*.php',
path + '**/*.php',
path + '**/**/*.php',
path + 'js/*.{js,json}',
path + 'js/**/*.{js,json}',
path + 'components/sass/*.{scss,sass}',
path + 'components/sass/**/*.{scss,sass}',
path + 'components/sass/**/**/*.{scss,sass}'],
options: {
livereload: true
}
},
// Scripts -
scripts: {
files: [
path + 'components/js/*.{js,json}'
],
tasks: ['uglify']
}, // scripts
},
sass: {
dist: {
options: {
sourceMap: true,
includePaths: [
require('node-bourbon').includePaths,
path + 'components/sass/*.{scss,sass}',
path + 'components/sass/**/*.{scss,sass}'
],
outputStyle: 'nested',
lineNumbers: true,
},
files: [
{src: path + 'components/sass/style.scss', dest: path + 'style.css'}
],
}
},
// Uglify
uglify: {
my_target: {
options: {
sourceMap: true,
sourceMapName: path + 'scripts.min.map'
},
files: [
{src: path + 'components/js/*.js', dest: path + 'js/scripts.min.js'}
],
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', 'watch');
};
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 24 (3 by maintainers)
Commits related to this issue
- Reduce CPU load (https://github.com/gruntjs/grunt-contrib-watch/issues/429) — committed to alexanderlaw/sqlfiddle2 by alexanderlaw 8 years ago
Have you tried this
Switching to https://github.com/JimRobs/grunt-chokidar (forked off of
grunt-contrib-watchbut useschokidarinstead ofgazefor file system watching) drops my CPU usage from ~25% to somewhere near 0% with the same functionality.@shama @tkellen Would you consider a pull request to switch the underlying lib from
gazetochokidar?I’m surprised this issue hasn’t gotten more attention. Tons of web developers are at coffee shops with no power and here grunt-watch-contrib is eating up battery.
FWIW chokidar is pretty horrible on Windows and as proof VSCode stopped using it years ago on windows and wrote their own. The do use chokidar on Linux and Mac or did last time I checked. For Windows they wrote some small C# program and read its streamed output
https://github.com/microsoft/vscode/tree/master/src/vs/platform/files/node/watcher/win32
We ended up switching away from
grunt-contrib-watch-based file watching to usepm2watchers (which usechokidarunder the hood) since we had to turn up the AC in the office to compensate for all the warm computers in the room caused by this issue 😬@vasilii-b grunt.option() is an interface for command line options. So
grunt.option('stack', true)in your Gruntfile is effectively the same asgrunt --stack.intervalis agrunt-contrib-watchtask option that is defined in theoptionsof the task itself: http://gruntjs.com/configuring-tasks#optionsUnfortunately your above Gruntfile is hiding the config so I’m not sure where that custom Gruntfile implementation expects watch task options. Typically with Gruntfiles, we recommend being explicit with the config: