Skip to content

Instantly share code, notes, and snippets.

@kanakiyajay
Created June 13, 2015 11:17
Show Gist options
  • Save kanakiyajay/c99012968248c630f18a to your computer and use it in GitHub Desktop.
Save kanakiyajay/c99012968248c630f18a to your computer and use it in GitHub Desktop.
This Gruntfile.js will clean your dist folder, concat & minify all js, css assets according config specified in html, put revisions, minify html and copy new folder structure to dist.
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
clean: ['dist'],
copy: {
generated: {
src: 'src/index.html',
dest: 'dist/index.html'
}
},
filerev: {
options: {
encoding: 'utf8',
algorithm: 'md5',
length: 20
},
source: {
files: [{
src: [
'dist/js/*.js',
'dist/css/*.css'
]
}]
}
},
useminPrepare: {
html: 'src/index.html',
options: {
dest: 'dist'
}
},
usemin: {
html: 'dist/index.html',
options: {
assetsDirs: ['dist', 'dist/css', 'dist/js', 'css', 'js']
}
},
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
}
});
grunt.registerTask('default', [
'clean',
'copy:generated',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'filerev',
'usemin',
'htmlmin'
]);
};
{
"name": "25-grunt-purifycss",
"version": "0.0.1",
"description": "Grunt plugin remove unused css",
"main": "Gruntfile.js",
"repository": {
"type": "git",
"url": "git://github.com/kanakiyajay/grunt-tasks.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jay Kanakiya",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.12.3",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-uglify": "^0.9.1",
"grunt-filerev": "^2.3.1",
"grunt-purifycss": "^0.1.0",
"grunt-usemin": "^3.0.0",
"load-grunt-tasks": "^3.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment