Skip to content

Instantly share code, notes, and snippets.

@cihadturhan
Created January 13, 2015 09:55
Show Gist options
  • Save cihadturhan/5e8c7f03185509f912c7 to your computer and use it in GitHub Desktop.
Save cihadturhan/5e8c7f03185509f912c7 to your computer and use it in GitHub Desktop.
// Whole Gruntfile.js so far
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.description %>\n' +
' *\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Copyright 2013-<%= grunt.template.today("yyyy") %>, <%= pkg.author %>\n' +
' * Released on: <%= grunt.template.today("mmmm d, yyyy") %>\n' +
'*/\n',
jshint: {
// define the files to lint
files: ['gruntfile.js', 'js/*.js', '!js/jquery*.js'],
// configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// more options here if you want to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true
}
}
},
clean: {
src: ["dist"],
},
uglify: {
options: {
report: 'gzip',
compress: true,
banner: '<%= banner %>',
},
mangle: {toplevel: false},
squeeze: {dead_code: false},
codegen: {quote_keys: true},
dist: {
files: {
'<%= pkg.dirs.js.dist.min %>':'<%= pkg.dirs.js.dist.src %>'
}
}
},
compress: {
main: {
options: {
mode: 'gzip',
level: 9
},
files: [
{expand: true, cwd: 'dist/', src: ['app.js', 'style.css'], dest: 'dist/zip/'}
]
}
},
concat: {
js: {
options: {
banner: '<%= banner %>',
stripBanners: true,
separator: ';\n'
},
src: '<%= pkg.dirs.js.dev %>',
dest: '<%= pkg.dirs.js.dist.src %>'
},
css:{
options: {
banner: '<%= banner %>',
stripBanners: true,
separator: ' \n'
},
src: '<%= pkg.dirs.css.dev %>',
dest: '<%= pkg.dirs.css.dist.src %>'
}
},
cssmin: {
options: {
banner: '<%= banner %>',
stripBanners: true,
separator: ' \n',
keepSpecialComments: 0
},
dist: {
files: {
'<%= pkg.dirs.css.dist.min %>':'<%= pkg.dirs.css.dist.src %>'
}
}
},
shell: {
echo: {
command: 'echo 1',
options: { stdout: true, failOnError: true }
},
clean: {
command: 'rm dist -r',
options: { stdout: true, failOnError: true }
},
pull: {
command: function(pr) {
return [
'git checkout .', //in case of any change
'git pull'
].join('&&');
},
options: {
stdout: true,
failOnError: true
}
}, amend: {
command: 'git commit -a --amend --no-edit',
options: { stdout: true, failOnError: true }
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress'); //gzip
grunt.loadNpmTasks('grunt-shell'); //git commands
grunt.registerTask('default', ['shell:pull', 'clean', 'concat:js', 'uglify', 'concat:css', 'cssmin', 'compress'])
};
{
"name": "product_name",
"charset": "UTF-8",
"author": "author",
"http_host": {
"dev": "/^localhost$/",
"dist": "/^productsite$/"
},
"dirs": {
"font": {
"dev": "res/fonts/",
"dist": "res/fonts/"
},
"css": {
"dev": [
"css/bs/bootstrap.css",
"css/bs/navbar.css",
"css/base.css",
"css/style.css",
"css/morph.css",
"css/datepicker3.css",
"css/jquery.timepicker.css",
"css/jquery.fancybox.css"
],
"dist": {
"src": "dist/css/style.src.css",
"min": "dist/style.css"
}
},
"js": {
"dev": [
"js/jquery-latest.min.js",
"js/bootstrap.js",
"js/packery/packery.pkgd.js",
"js/datepicker/bootstrap-datepicker.js",
"js/jquery.timepicker/jquery.timepicker.js",
"js/helper.js",
"js/d3-custom.js",
"js/colorbrewer.js",
"js/prefixfree.min.js",
"js/moment.dev.min.js",
"js/jquery.balanced-gallery.js",
"js/jquery.lazyload/jquery.lazyload.min.js",
"js/jquery.fancybox/jquery.fancybox.js",
"js/general.js"
],
"dist": {
"src": "dist/js/app.src.js",
"min": "dist/app.js"
}
}
},
"title": "Product title",
"homepage": "product website",
"description": "Product description",
"version": "1.0.3",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-cssmin": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-compress": "~0.9.1",
"grunt-shell": "~0.5.0",
"time-grunt": "~0.2.8",
"rebuild": "^0.1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment