gruntjs / grunt

Grunt: The JavaScript Task Runner
http://gruntjs.com/
Other
12.27k stars 1.5k forks source link

High CPU-Usage with grunt 1.0.1 #1593

Open nordentwickler opened 7 years ago

nordentwickler commented 7 years ago

Hello, i'm having 100% CPU-Usage with my grunt configuration. All i could read about this issue is outdated and so i would be very thankful if anybody could help.

The Node-Version is: 7.10.0

My Gruntfile.js:

module.exports = function(grunt) {
    require('load-grunt-tasks')(grunt);
    grunt.initConfig({
        // Copy files
        copy: {
            essentialregular: {
                expand: true,
                cwd: 'source/fonts/essential-regular',
                src: '**/*.{otf,eot,svg,ttf,woff,woff2}',
                dest: 'assets/fonts/essential-regular/',
                filter: 'isFile',
            },
            glyphicons: {
                expand: true,
                cwd: 'node_modules/bootstrap/fonts',
                src: '**/*.{otf,eot,svg,ttf,woff,woff2}',
                dest: 'assets/fonts/glyphicons/',
                filter: 'isFile',
            },
        },

        // Image compression
        imagemin: {
            options: {
                optimizationLevel: 3,
                svgoPlugins: [{removeViewBox: false}],
            },
            img: {
                expand: true,
                cwd: 'source/img/',
                src: '**/*.{png,jpg,jpeg,gif,svg,ico}',
                dest: 'assets/img/',
            },
            slick: {
                expand: true,
                cwd: 'node_modules/slick-carousel/slick/',
                src: 'ajax-loader.gif',
                dest: 'assets/img/',
            },
        },

        // CSS Compiling
        less: {
            options: {
                sourceMap: true,
            },
            dist: {
                files: {
                    'assets/css/main.css': 'source/less/_main.less',
                },
            },
        },

        postcss: {
            options: {
                map: {
                    inline: false,
                },
                processors: [
                    require('autoprefixer')({browsers: '> 1%'}),
                    require('cssnano')(),
                ],
            },
            dist: {
                src: 'assets/css/*.css',
            },
        },

        // Browserify javascript files
        browserify: {
            options: {
                browserifyOptions: {
                    debug: true,
                },
            },
            dist: {
                files: {
                    'assets/js/main.js': 'source/js/_main.js',
                },
            },
        },

        // JS Minimizing
        uglify: {
            options: {
                sourceMap: true,
            },
            dist: {
                files: {
                    'assets/js/main.js': 'assets/js/main.js',
                },
            },
        },

        // Watching Tasks
        watch: {
            options:{
                interval:300,
            },
            fonts: {
                files: [
                    'node_modules/bootstrap/fonts/**/*.{otf,eot,svg,ttf,woff,woff2}',
                    'source/fonts/**/*.{otf,eot,svg,ttf,woff,woff2}',
                    'source/fonts/**/*.less',
                ],
                tasks: ['fonts', 'css'],
            },
            img: {
                files: 'source/img/**/*.{png,jpg,jpeg,gif,svg,ico}',
                tasks: ['img'],
            },
            css: {
                files: 'source/less/**/*.less',
                tasks: ['css'],
            },
            js: {
                files: 'source/js/**/*.js',
                tasks: ['js'],
            },
            express: {
                files: ['!node_modules/**/*.*'],
            },
        },

        // browserSync
        browserSync: {
            dev: {
                bsFiles: {
                    src: [
                        'assets/fonts/**/*.{otf,eot,svg,ttf,woff,woff2}',
                        'assets/img/**/*.{png,jpg,jpeg,gif,svg}',
                        'assets/css/**/*.css',
                        'assets/js/**/*.js',
                        '**/*.{html,php}',
                    ],
                },
                options: {
                    notify: false,
                    watchTask: true,
                    proxy: "tdh:8888",
                }
            }
        }

    });

    grunt.registerTask('fonts', ['copy:essentialregular', 'copy:glyphicons']);
    grunt.registerTask('img',   ['imagemin']);
    grunt.registerTask('css',   ['less', 'postcss']);
    grunt.registerTask('js',    ['browserify', 'uglify']);

    // default task for building all files
    grunt.registerTask('default', ['fonts', 'img', 'css', 'js']);

    // serve task to serve in browser and watch for changes
    grunt.registerTask('serve', ['default', 'browserSync', 'watch']);
};

My package.json


{
  "name": "grunt-boilerplate",
  "description": "description",
  "repository": {
    "type": "git",
    "url": "git-url"
  },
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "watch": "grunt serve",
    "build": "grunt"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.1",
    "cssnano": "^3.10.0",
    "grunt": "^1.0.1",
    "grunt-browser-sync": "^2.2.0",
    "grunt-browserify": "^5.0.0",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-imagemin": "^1.0.1",
    "grunt-contrib-less": "^1.4.1",
    "grunt-contrib-uglify": "^2.3.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-postcss": "^0.8.0",
    "load-grunt-tasks": "^3.5.2"
  },
  "dependencies": {
    "bootstrap": "^3.3.7",
    "jquery": "^3.2.1",
    "openshare": "^1.4.10",
    "parsleyjs": "^2.7.2",
    "slick-carousel": "^1.6.0"
  }
}
iharosi commented 7 years ago

Hi,

I've experienced the same on macOS Sierra with grunt@1.0.1, then I dowgraded grunt to version 1.0.0 and the high CPU usage has disappeared.

» node -v
v6.11.2

» npm -v
3.10.10
Falcikas commented 3 years ago

I had a similar freezes and high CPU usage and my problem was in grunt-contrib-watch plugin. I've set spawn parameter to false on watch tasks - options.spawn