chemitaxis
chemitaxis

Reputation: 14937

Multiple folder and files with Grunt

I'm working with Grunt to minified JS. I need to minified differents folder for different pages... for example workspace.min.js for the Workspace page, and dashboard.min.js for Dashboard page...

How I need to configure my gruntfile? Can I add in my grunt file task for minified the CSS files too?

I put the actual code here for my gruntfile.js! (I'm very new with Grunt... sorry)

Thanks!!

module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    paths: {
        src: {
            js: ['Resources/js/workspace/*.js', 'Resources/plugins/redactor/*.js', 'Resources/plugins/jquery.cookie/jquery.cookie.js',
                '/Resources/plugins/holder/holder.js', '/Resources/plugins/jquery.numeric/jquery.numeric.min.js', '/Resources/plugins/smothZoom/jquery.smoothZoom.js',
            '/Resources/plugins/jquery-transit/jquery.transit.min.js','']
        },
        dest: {
            js: 'dist/workspace.js',
            jsMin: 'dist/workspace.min.js'
        }
    },
    concat: {
        js: {
            options: {
                separator: ';'
            },
            src: '<%= paths.src.js %>',
            dest: '<%= paths.dest.js %>'
        }
    },
    uglify: {
        options: {
            banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
            compress: true,
            mangle: true,
            sourceMap: true
        },
        build: {
            src: '<%= paths.src.js %>',
            dest: '<%= paths.dest.jsMin %>'
        }
    }
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s).
grunt.registerTask('default', ['uglify']);

};

Upvotes: 1

Views: 348

Answers (1)

user488187
user488187

Reputation:

If you want to minify a number of files, you can create multiple keys like:

    uglify: {
        scripts: {
            files:{
                '<%= dirs.dest%>/js/scripts.min.js': [
                    '<%= dirs.src%>/js/scripta.js',
                    '<%= dirs.src%>/js/scriptb.js',
                    '<%= dirs.src%>/js/scriptc.js'
                    ]
            }
        },
        someotherscript: {
            files:{
                '<%= dirs.dest %>/js/scriptd.min.js': '<%= dirs.src %>/js/scriptd.js'
            }
        }
    }

And then create a default task to run them all, like:

grunt.registerTask(
    'default',
    [
    'uglify:scripts',
    'uglify:someotherscript',
    ]
);

Then when you run grunt, it minifies them all.

Upvotes: 1

Related Questions