schwertfisch
schwertfisch

Reputation: 4579

Grunt Uglify some scripts

I want to uglify some specifics js from my angularjs project. I don't want uglify al js path.

I tried with this

 src : 'www/js/app.js', 'www/js/controllers.js', 'www/js/directives.js', 'www/js/factories.js', 'www/js/filters.js', 'www/js/services.js',

and this

src : 'www/js/app.js, www/js/controllers.js, www/js/directives.js, www/js/factories.js, www/js/filters.js, www/js/services.js',

and not luck.

module.exports = function(grunt){
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks("grunt-contrib-uglify");

    grunt.initConfig({
        clean : [ 'www/dist/*' ],
        uglify : {
            options : {
                report : 'min',
                mangle : true
            },
            my_target : {
                files : [ {
                    src : 'www/js/app.js, www/js/controllers.js, www/js/directives.js, www/js/factories.js, www/js/filters.js, www/js/services.js',
                    dest : 'www/dist/app.realease.min.js'
                } ]
            }
        }
    })

    grunt.registerTask('default', ['clean', 'uglify']);
}

If somebody can help me I apreciate too much your help.

Thanks.

Upvotes: 0

Views: 105

Answers (1)

Preview
Preview

Reputation: 35796

Your problem is that you give a simple string listing files, where you should give an array of string for each file you want to target.

src : 'www/js/app.js', 'www/js/controllers.js', 'www/js/directives.js', 'www/js/factories.js', 'www/js/filters.js', 'www/js/services.js'

should become

src : ['www/js/app.js', 'www/js/controllers.js', 'www/js/directives.js', 'www/js/factories.js', 'www/js/filters.js', 'www/js/services.js']

But for me you should concat your files in one and then uglify it like this :

module.exports = function(grunt) {

    grunt.initConfig({

        clean : [ 'www/dist/*' ],
        concat: {
            options: {
                separator: ';'
            },
            dist: {
                src: ['www/js/app.js', 'www/js/controllers.js', 'www/js/directives.js', 'www/js/factories.js', 'www/js/filters.js', 'www/js/services.js'],
                dest: 'www/dist/app.release.js'
            }
        },
        uglify: {
            options: {
                mangle: false
            },
            dist: {
                files: {
                    'dist/app.release.min.js': ['<%= concat.dist.dest %>']
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');

    grunt.registerTask('default', ['clean', 'concat', 'uglify']);

};

Upvotes: 1

Related Questions