I am trying to build AngularJS project with grunt (Ubuntu 14.04), but when running it eats 100% CPU is extremely slow.
Here is my grunfile
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']);
};
I have been using the same for a while without any problem, and all was fine! It has started by a sudden and I tried several things to boosting it without any result. I assume it is not connected with the grunt itself, but more to the system which I am using (it's fine on other OS's). What can be a problem?
UPDATE:
After re-installing grunt-contrib-uglify
everything seems to be fine. Still uglify
task takes one minute to completed, but that more or less fine, considering the amount my modules to be compiled.
You can use time-grunt
to output data about which task is causing the problem. You can then focus your efforts on optimizing that particular task.
https://github.com/sindresorhus/time-grunt
Disclosure: This is a boss library that I have nothing to do with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With