angularjs - Grunt son derece yavaş - %100 cpu


Grunt ile AngularJS projesi oluşturmaya çalışıyorum (Ubuntu 14.04), ancak çalıştırdığımda %100 CPU kullanıyor ve son derece yavaş.

İşte benim grunfile'ım

module.exports = function (grunt) {

    grunt.loadNpmTasks('grunt-typescript');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-karma');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-compress');

    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        typescript: {           
            home: {
                src: ['src/routes/home.ts'],
                dest: 'build/compiled_app/routes/home.js',
                options: {
                    ignoreTypeCheck: false
                }
            },
            controller_tests: {
                src: ['tests/unit/controller/*Test.ts'],
                dest: 'tests/build',
                options: {
                    ignoreTypeCheck: false
                }
            },
            services_tests: {
                src: ['tests/unit/services/*.ts'],
                dest: 'tests/build/ServicesTests.js',
                options: {
                    ignoreTypeCheck: false
                }
            },
            filters_tests: {
                src: ['tests/unit/filters/*.ts'],
                dest: 'tests/build/FiltersTests.js',
                options: {
                    ignoreTypeCheck: false
                }
            }
        },

        less: {
            options: {
                paths: ['src/less'],
                yuicompress: true,
                nospawn: true,
                livereload: true
            },
            compile: {
                expand: true,
                cwd: 'src/less',
                src: '**/*.less',
                dest: 'build/assets/css/',
                ext: '.css'
            }
        },

        copy: {
            assets: {
                expand: true,
                cwd: 'assets/',
                src: ['**', '!root_content/**'],
                dest: 'build/assets'
            },
            root_content: {
                expand: true,
                cwd: 'assets/root_content/',
                src: '**',
                dest: 'build/'
            },
            min_js: {
                expand: true,
                cwd: 'build/compiled_app/',
                src: ['**/*.js', '*.js'],
                dest: 'build/compiled_app/',
                ext: '.min.js'
            }
        },

        htmlmin: {
            options: {
                removeComments: true,
                collapseWhitespace: true
            },
            app_pages: {
                expand: true,
                cwd: 'pages/',
                src: ['**/*.html', '*.html'],
                dest: 'build/'
            },
            app_views: {
                expand: true,
                cwd: 'src/views',
                src: ['**/*.html', '*.html'],
                dest: 'build/compiled_app/views',
                filter: 'isFile'
            }
        },

        uglify: {
            options: {
                mangle: false
            },
            app: {
                expand: true,
                cwd: 'build/compiled_app/',
                src: '**/*.js',
                dest: 'build/compiled_app/',
                ext: '.min.js'
            }
        },

        karma: {
            unit: {
                basePath: '',
                frameworks: ['jasmine'],
                files: [
                    {pattern: 'tests/assets/javascripts/jquery-1.7.2.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-route.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-resource.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-cookies.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-ipcookie.min.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-mocks.js', included: true},
                    {pattern: 'tests/assets/javascripts/async.min.js', included: true},
                    {pattern: 'tests/assets/javascripts/underscore-min.js', included: true},
                    {pattern: 'assets/javascripts/ng-infinite-scroll.js', included: true},
                    {pattern: 'assets/javascripts/ui-bootstrap-0.6.0.min.js', included: true},
                    {pattern: 'assets/javascripts/angular-strap.min.js', included: true},
                    {pattern: 'build/compiled_app/*.js', included: true},
                    {pattern: 'build/compiled_app/routes/*.js', included: true},
                    {pattern: 'tests/build/**/*.js', included: true}
                ],
                preprocessors: { '**/tests/build/src/**/*.js': 'coverage' },
                reporters: ['progress', 'coverage', 'junit'],
                singleRun: true,
                browsers: ['PhantomJS'],
                coverageReporter: {
                    type: 'cobertura',
                    dir: 'tests/coverage/'
                },
                junitReporter: {
                    outputFile: 'tests/coverage/test-results.xml',
                    suite: ''
                }
            },
            e2e: {
                basePath: '',
                files: [
                    {pattern: 'tests/assets/javascripts/jquery-1.7.2.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-route.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-resource.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-cookies.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-ipcookie.min.js', included: true},
                    {pattern: 'tests/assets/javascripts/angular-mocks.js', included: true},
                    {pattern: 'tests/assets/javascripts/async.min.js', included: true},
                    {pattern: 'tests/assets/javascripts/underscore-min.js', included: true},
                    {pattern: 'assets/javascripts/ng-infinite-scroll.js', included: true},
                    {pattern: 'build/compiled_app/*.js', included: true},
                    {pattern: 'build/compiled_app/routes/*.js', included: true},
                    {pattern: 'tests/e2e/*.js', included: true}
                ],
                autoWatch: false,
                browsers: ['Chrome'],
                frameworks: ['ng-scenario'],
                singleRun: true,                
                plugins: [
                    'karma-junit-reporter',
                    'karma-chrome-launcher',
                    'karma-firefox-launcher',
                    'karma-jasmine',
                    'karma-ng-scenario'
                ],
                junitReporter: {
                    outputFile: 'test_out/e2e.xml',
                    suite: 'e2e'
                }
            }
        },

        clean: {
            output: ['build/', 'tests/build', 'tests/coverage']
        },


        watch: {

            typescript: {
                files: ['src/**/*.ts'],
                tasks: ['package-js'],
                options: {
                    debounceDelay: 500
                }
            },
            // Watch task for html partials and main pages
            // It calles task to package html in correct folder
            html: {
                files: ['src/**/*.html', 'pages/**/*.html'],
                tasks: ['package-html'],
                options: {
                    debounceDelay: 500
                }
            },
            // Watch task for less files. Will execute task to compile
            // less files and package them in correct folder
            less: {
                files: ['src/**/*.less'],
                tasks: ['package-less'],
                options: {
                    debounceDelay: 500
                }
            }

        },

        compress: {
            main: {
                options: {
                    mode: 'tgz',
                    archive: 'build/landing.tar.gz'
                },
                expand: true,
                cwd: 'build',
                src: ['**/*'],
                pretty: true
            }
        }

    });


    grunt.registerTask('package-js', ['typescript', 'copy:min_js']);
    grunt.registerTask('package-html', ['htmlmin']);
    grunt.registerTask('package-less', ['less']);

    grunt.registerTask('compile', ['less', 'typescript']);
    grunt.registerTask('app', ['compile', 'htmlmin:app_pages', 'htmlmin:app_views']);
    grunt.registerTask('assets', ['copy:assets', 'copy:root_content']);
    grunt.registerTask('package', ['app', 'assets', 'uglify:app']);
    grunt.registerTask('default', ['clean', 'package']);
    grunt.registerTask('build', ['default', 'compress']);
    grunt.registerTask('test', ['clean', 'typescript', 'karma:unit']);
    grunt.registerTask('tests', ['test']);
    grunt.registerTask('dev', ['app', 'copy:min_js']);

};

Bir süredir aynı şeyi sorunsuz bir şekilde kullanıyordum ve her şey yolundaydı! Aniden başladı ve onu hızlandırmak için birkaç şey denedim ama hiçbir sonuç alamadım. Bunun doğrudan grunt ile ilgili olmadığını, kullandığım sistemle daha çok ilgili olduğunu düşünüyorum (diğer işletim sistemlerinde sorun yok). Sorun ne olabilir?

GÜNCELLEME:

grunt-contrib-uglify yeniden yükledikten sonra her şey yolunda görünüyor. Yine de uglify görevinin tamamlanması bir dakika sürüyor, ama derlenecek modüllerimin miktarını göz önünde bulundurursak bu aşağı yukarı normal.

Cevap #1

time-grunt'u hangi görevin soruna neden olduğunu gösteren verileri çıkarmak için kullanabilirsiniz. Daha sonra çabalarınızı o belirli görevi optimize etmeye odaklayabilirsiniz.

https://github.com/sindresorhus/time-grunt

Açıklama: Bu, benimle ilgisi olmayan bir patron kütüphanesidir.

Cevap #2

Tüm paketleri güncellemeye eğilimli olurdum. Ben grunt-ts ekibinde çalışıyorum ve dosya izleme özelliğinin rastgele hem karma'nın kullandığı watch kütüphanesiyle hem de grunt-watch'in kullandığıyla %100 CPU vermesi sorununu yaşadık.

İlgili makaleler