javascriptnode.jsgruntjsuglifyjsgrunt-concurrent

uglify with grunt-concurrent not working


I'm trying to use grunt-concurrent to minify my javascript files in parallel. I also use usemin and ngmin.

When I use uglify without grunt-concurrent I get the expected result with this log output:

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.

But when I try to execute this tasks using grunt-concurrent with that configuration:

    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'
        ]
    },

I get the message that this tasks are not configured:

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.

My build task configuration ist this:

    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'
]);

The Question is, how can I make use of grunt-concurrent with uglify and usemin/ngmin?


Solution

  • usemin adds tasks to uglify on the fly but they are for whatever reason not visible in grunt-concurrent. To solve this, you have to manually add the files to 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"
        },
    

    The problem is, that this is not dry. you have to configure it in the index.html, in grunt-concurrent and here in uglify..