Skip to content

Instantly share code, notes, and snippets.

@duvillierA
Last active December 27, 2015 20:49
Show Gist options
  • Save duvillierA/7387477 to your computer and use it in GitHub Desktop.
Save duvillierA/7387477 to your computer and use it in GitHub Desktop.
Sample Gruntfile
module.exports = function(grunt) {
/*
Tree :
src/less/\*\/*.less
src/scripts/\*\/*.js
dist/js/*.min.js == test+concat+minify
dist/js/*.js == test+concat+beautify
dist/css/*.css == compile+beautify
dist/css/*.min.css == compile+minify
*/
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/**/*.js'],
dest: 'dist/js/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n\n'
},
dist: {
options : {
report: 'min'
},
files: {
'dist/js/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
}
},
beautify: {
options : {
compress: false,
beautify: true,
preserveComments: 'some'
},
files: {
'<%= concat.dist.dest %>': ['<%= concat.dist.dest %>']
}
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
connect: {
options: {
port: 8000,
hostname: 'localhost',
base:'..',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.'
]
}
}
},
watch: {
js : {
files: ['<%= jshint.files %>'],
tasks: ['jshint', 'concat', 'uglify']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= jshint.files %>'
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('test', ['jshint']);
grunt.registerTask('dist-js', ['concat', 'uglify']);
grunt.registerTask('default', ['test', 'dist-js']);
grunt.registerTask('server', ['connect', 'watch']);
};
{
"name": "try_grunt",
"version": "0.0.0",
"description": "try grunt",
"main": "gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-recess": "~0.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment