Using grunt to concat and minify css and js

2015-08-23 23:00:00
Posted in: Development
Views: 3219

with grunt the javascript task runner we can monitor for changes


Grunt automnaticy generates the files when changes are detected.


More plugins are available on: http://gruntjs.com/plugins


module.exports = function (grunt) {  
    require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);  
    // Project configuration.  
    grunt.initConfig({  
        pkg: grunt.file.readJSON('package.json'),  
       
         jshint: {
      files: ['Gruntfile.js', 'node_modules/jquery/src/*.js', 'node_modules/bootstrap/js/*.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    }, 
    watch: {
      files: ['<%= jshint.files %>'],
      tasks: ['jshint']
    },
        
         

		
	concat: {	
		options: {
			separator: ';'
		},
		dist: {
			src: [  
                  'assets/jquery-1.10.2.min.js',
                  'assets/jquery-ui.min.js',
                  'assets/bootstrap-3.3.5-dist/js/bootstrap.min.js',
                  'assets/jquery.bootstrap-autohidingnavbar.min.js'
                  ],
			dest: 'dist/<%= pkg.name %>.core.min.js'
			}
		
		},
    
    
    
    uglify: {
		  options: {
			// the banner is inserted at the top of the output
			banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
		  },
		  dist: {
			files: {
			  'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
			}
		  }
		},
    
    
    
	cssmin: {  
		sitecss: {  
			options: {  
				shorthandCompacting: false,
				roundingPrecision: -1
				},  
                files: {  
                    'dist/<%= pkg.name %>.min.css': [
											'assets/bootstrap-3.3.5-dist/css/bootstrap.css',
											'assets/font-awesome-4.3.0/css/font-awesome.css',
											'assets/simple-parallax-effect-source/css/base.css',  
											'assets/simple-parallax-effect-source/css/style.css',  
											'assets/jquery-ui.min.css',      
											'assets/why-guy.css'
											]  
                }  
            }  
        },     
    });
    grunt.loadNpmTasks('grunt-contrib-concat','grunt-contrib-cssmin','grunt-contrib-uglify');

    // Default task.  
    grunt.registerTask('default', ['cssmin','concat','uglify']);  
    
    
};

why-guy add:

Last Tweets: