Skip to content

Instantly share code, notes, and snippets.

@tlindig
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlindig/8972342 to your computer and use it in GitHub Desktop.
Save tlindig/8972342 to your computer and use it in GitHub Desktop.
Example Gruntfile.js with template for banner and some other usfull common configuration.
/*global module:false*/
module.exports = function(grunt) {
"use strict"; //enable ECMAScript 5 Strict Mode
// overwrite platform specific setting get always unix like line feed char
grunt.util.linefeed = '\n';
// Project configuration.
grunt.initConfig({
// global properties
pkg: (function() {
var prop = grunt.file.readJSON('package.json');
prop.build = {
year: grunt.template.today('yyyy'),
date: grunt.template.today('yyyy-mm-dd'),
time: grunt.template.today('HH:MM')
};
return prop;
})(),
banner: [
'/*!',
' * <%= pkg.title || pkg.name %> - <%= pkg.description %>',
' *',
' * v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>',
' *',
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>',
' * <%= pkg.author.url %>',
' *',
' * License: <%= pkg.license %>',
' *',
' * Author: <%= (typeof pkg.author === "string") ? pkg.author : (pkg.author.name + " <" + pkg.author.email + ">") %>',
' */\n'
].join('\n'),
// task configuration
// Task configuration.
clean: {
files: ['dist']
},
concat: {
options: {
banner: '<%= banner %>',
stripBanners: true
},
dist: {
src: ['src/<%= pkg.name %>.js'],
dest: 'dist/<%= pkg.name %>.js'
}
},
uglify: {
options: {
banner: '<%= banner %>'
},
dist: {
src: '<%= concat.dist.dest %>',
dest: 'dist/<%= pkg.name %>.min.js'
}
},
jshint: {
gruntfile: {
options: {
jshintrc: '.jshintrc'
},
src: 'Gruntfile.js'
},
src: {
options: {
jshintrc: 'src/.jshintrc'
},
src: ['src/**/*.js']
}
}
});
// Load plugins provide necessary task.
require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
// Default task.
grunt.registerTask('default', ['jshint', 'clean', 'concat', 'uglify']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment