gpt4 book ai didi

angularjs - Grunt 非常慢 - 100% cpu

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:27 25 4
gpt4 key购买 nike

我正在尝试使用 grunt (Ubuntu 14.04) 构建 AngularJS 项目,但是当它运行时占用 100% CPU 非常慢。

这是我的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']);

};

我已经用了一段时间了,没有任何问题,一切都很好!它突然开始,我尝试了几种方法来增强它但没有任何结果。我认为它与 grunt 本身无关,而是与我正在使用的系统有关(在其他操作系统上没问题)。什么是问题?

更新:

重新安装 grunt-contrib-uglify 后一切似乎都很好。 uglify 任务仍然需要一分钟才能完成,但考虑到要编译的模块数量,这或多或少没问题。

最佳答案

您可以使用 time-grunt 输出有关导致问题的任务的数据。然后,您可以集中精力优化该特定任务。

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

披露:这是一个与我无关的 boss 库。

关于angularjs - Grunt 非常慢 - 100% cpu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28503800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com