uglify与grunt-concurrent无法正常工作

时间:2014-10-07 12:52:44

标签: javascript node.js gruntjs uglifyjs grunt-concurrent

我正在尝试使用grunt-concurrent来并行缩小我的javascript文件。我也使用usemin和ngmin。

当我使用没有grunt-concurrent的uglify时,我得到了这个日志输出的预期结果:

Running "uglify:dist" (uglify) task

Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task
File dist/scripts/jquery_and_angular.js created.

Running "uglify:dist/scripts/external-non-angular-libraries.js" (uglify) task
File dist/scripts/external-non-angular-libraries.js created.

Running "uglify:dist/scripts/modules.js" (uglify) task
File dist/scripts/modules.js created.

Running "uglify:dist/scripts/scripts.js" (uglify) task
File dist/scripts/scripts.js created.

但是当我尝试使用grunt-concurrent与该配置执行此任务时:

    concurrent: {
        lessAndMinify: [
            'ngmin',
            'less'
        ],
        uglify: [
            'uglify:dist/scripts/jquery_and_angular.js',
            'uglify:dist/scripts/external-non-angular-libraries.js',
            'uglify:dist/scripts/modules.js',
            'uglify:dist/scripts/scripts.js',
            'uglify:dist/scripts/templates.js'
        ]
    },

我收到的消息是未配置此任务:

Running "concurrent:uglify" (concurrent) task
Warning: Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task
Verifying property uglify.dist/scripts/jquery_and_angular\.js exists in config...ERROR
>> Unable to process task.
Warning: Required config property "uglify.dist/scripts/jquery_and_angular\.js" missing. Use --force to continue.

Aborted due to warnings. Used --force, continuing.

Running "uglify:dist/scripts/jquery_and_angular.js" (uglify) task
Verifying property uglify.dist/scripts/jquery_and_angular\.js exists in config...ERROR
>> Unable to process task.
Warning: Required config property "uglify.dist/scripts/jquery_and_angular\.js" missing. Use --force to continue.

Aborted due to warnings.
    Warning: Running "uglify:dist/scripts/modules.js" (uglify) task
Verifying property uglify.dist/scripts/modules\.js exists in config...ERROR
>> Unable to process task.
Warning: Required config property "uglify.dist/scripts/modules\.js" missing. Use --force to continue.

Aborted due to warnings. Used --force, continuing.

Running "uglify:dist/scripts/modules.js" (uglify) task
Verifying property uglify.dist/scripts/modules\.js exists in config...ERROR
>> Unable to process task.
Warning: Required config property "uglify.dist/scripts/modules\.js" missing. Use --force to continue.

我的构建任务配置是这样的:

    grunt.registerTask('build', [
    'clean:dist',
    'ngtemplates',
    'copy:indexHtml',
    'replace',
    'useminPrepare',
    'concat',
    'copy:dist',
    'copy:generated',
    'concurrent:lessAndMinify', // ngmin and less
//  'concurrent:uglify',
    'uglify',
    'rev',
    'usemin'
]);

问题是,如何使用grunt-concurrent与uglify和usemin / ngmin?

1 个答案:

答案 0 :(得分:0)

usemin将任务添加到uglify中,但它们出于任何原因在grunt-concurrent中不可见。 要解决此问题,您必须手动将文件添加到uglify:

    uglify: {
        dist: {
            options: {
                sourceMap: true
            },
            files: {
            }
        },

        // you have to add this manually!
        "dist/scripts/jquery_and_angular.js": "dist/scripts/jquery_and_angular.js",
        "dist/scripts/external-non-angular-libraries.js": "dist/scripts/external-non-angular-libraries.js",
        "dist/scripts/modules.js": "dist/scripts/modules.js",
        "dist/scripts/scripts.js": "dist/scripts/scripts.js",
        "dist/scripts/templates.js": "dist/scripts/templates.js"
    },

问题是,这不是干的。你必须在index.html,grunt-concurrent和uglify ..

中配置它