Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active August 29, 2015 14:26
Show Gist options
  • Save sarathlal-old/69f78c4c1707dfa92e3f to your computer and use it in GitHub Desktop.
Save sarathlal-old/69f78c4c1707dfa92e3f to your computer and use it in GitHub Desktop.
Configure few task on Gruntfile.js
// configure jshint to validate all js files -----------------------------------
jshint: {
options: {
reporter: require('jshint-stylish') // use jshint-stylish to make our errors look and read good
},
// when this task is run, lint the Gruntfile and all js files in src
build: ['src/js/*.js']
}
// configure uglify to minify single js file
uglify: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
files: {
'dist/js/magic.min.js': 'src/js/magic.js'
}
}
}
//Minify multiple js files in to one file
uglify: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
src : 'src/js/*.js',
dest : 'dest/js/build.js'
}
}
//Minify multiple js files separately
uglify: {
files: {
src: 'src/js/*.js', // source files mask
dest: 'dest/js/', // destination folder
expand: true, // allow dynamic building
flatten: true, // remove all unnecessary nesting
ext: '.min.js' // replace .js to .min.js
}
}
//Concat files
concat: {
options: {
// define a string to put between each file in the concatenated output
separator: ';'
},
dist: {
src: ['src/**/*.js'], // the files to concatenate
dest: 'dist/<%= pkg.name %>.js' // the location of the resulting JS file
}
}
//Minimize images
imagemin: {
dist: {
options: {
optimizationLevel: 5
},
files: [{
expand: true,
cwd: 'src/img/images',
src: ['**/*.{png,jpg,gif}'],
dest: 'dist/img/'
}]
}
}
//Remove unused css selectors from stylesheet.
//ignore : specify a list of selectors that should not be removed
//ignoreSheets : that allows us to specify style sheets to ignore
uncss: {
dist: {
options: {
ignore: [/js-.+/, '.special-class'],
ignoreSheets: [/fonts.googleapis/],
},
files: {
'dist/css/unused-removed.css': ['src/index.html', 'src/contact.html', 'src/service.html']
}
}
}
//Minify HTML
//process all the pages placed in the “src” directory and its subfolders.
//For each of these pages, the task removes all the comments and collapses the spaces it finds.
//store the results in the “dist” directory
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: 'src',
src: '**/*.html',
dest: 'dist/'
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment