0

我正在尝试使用 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 结合使用?

4

1 回答 1

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 中配置它。

于 2014-10-07T14:31:41.550 回答