Last active
August 29, 2015 13:56
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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