Skip to content

Instantly share code, notes, and snippets.

@shankscript
Created October 31, 2015 16:21
Show Gist options
  • Save shankscript/9c0cf098ada9f68c180b to your computer and use it in GitHub Desktop.
Save shankscript/9c0cf098ada9f68c180b to your computer and use it in GitHub Desktop.
A sample Gruntfile
var timer = require('grunt-timer');
module.exports = function (grunt) {
'use strict';
//timer.init(grunt);
timer.init(grunt, {
deferLogs: true,
friendlyTime: true,
color: 'blue'
});
// Project configuration.
grunt.initConfig({
clean: {
release: {
src: ['bin/*', 'doc/*']
},
default: {
src: ['bin/*']
},
doc: {
src: ['doc/*']
}
},
jshint: {
default: {
options: {
/*reporter: require('jshint-stylish'),*/
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
$: true,
amplitude: true,
window: true,
angular: true,
localString: true,
locale: true,
console: true,
AMP_EVENTS: true
}
},
src: ['*.js', 'public/**/*.js', '!build/', '!node_modules/', '!Gruntfile.js', '!public/js/vendor/*.js']
}
},
uglify: {
default: {
options: {
mangle: true
},
files: [{
expand: true,
cwd: 'public',
src: ['**/*.js'],
dest: 'bin/build/'
}]
},
release: {
options: {
mangle: true
},
src: [
"public/js/vendor/angular.min.js",
"public/js/vendor/angular-cookies.min.js",
"public/js/vendor/angular.ui.router.min.js",
"public/js/vendor/ui-bootstrap-tpls-0.13.0.min.js",
"public/js/vendor/jquery-2.1.3.min.js",
"public/js/vendor/load-image.all.min.js",
"public/js/vendor/bootstrap.min.js",
"public/js/vendor/angular.touch.js",
"public/js/vendor/angular-carousel.min.js",
"public/js/vendor/angular.animate.js",
"public/js/vendor/angular-sanitize.js",
"public/js/vendor/angulartics.min.js",
"public/js/vendor/angulartics-facebook-pixel.min.js",
"public/js/app/stub.data.js",
"public/js/app/providers/stubFactory.js",
"public/js/app/constants.js",
"public/js/app/services.js",
"public/js/app/controllers.js",
"public/js/app/providers/CartService.js",
"public/js/app/providers/CheckoutService.js",
"public/js/app/providers/CLService.js",
"public/js/app/catalog/CatalogCtrl.js",
"public/js/app/catalog/DetailCtrl.js",
"public/js/app/catalog/DisplayCtrl.js",
"public/js/app/cart/CartCtrl.js",
"public/js/app/checkout/CheckoutCtrl.js",
"public/js/app/status/OrdersCtrl.js",
"public/js/app/modal/ModalDirective.js",
"public/js/app/directives.js",
"public/js/app/app.js"
],
dest: 'bin/build/js/finale.all.min.js'
}
},
/*
*/
htmlmin: { // Task
default: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: 'public',
src: ['**/*.html', '!public/index.html'],
dest: 'bin/build/'
}]
},
release: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: 'public',
src: ['**/*.html', '!public/index.html'],
dest: 'bin/build/'
}
/*, {
src: ['public/index.html.tmpl'],
dest: 'bin/build/index.html'
}*/
]
}
},
cssmin: { // Task
default: { // Target
files: [{
expand: true,
cwd: 'public',
src: '**/*.css',
dest: 'bin/build/'
}]
},
release: {
src: ["public/css/bootstrap.min.css",
"public/css/angular-carousel.css",
"public/css/styles.css",
"public/css/bootstrap.extend.css",
"public/css/schneider-fonts.css",
"public/css/desktop.css"
],
dest: 'bin/build/css/fijnale.all.min.css'
}
},
imagemin: { // Task
default: { // Target
files: [{
expand: true,
cwd: 'public',
src: ['**/*.{png,jpg,gif}'],
dest: 'bin/build/'
}]
}
},
copy: { // Task
default: { // Target
files: [{
expand: true,
cwd: 'public',
src: ['**/*.{ttf,svg,eot,woff}', '**/*.{png,gif,jpg,jpeg,xml,txt}'],
dest: 'bin/build/'
}]
},
release: { // Target
files: [{
expand: true,
cwd: 'public',
src: ['**/*.{ttf,svg,eot,woff,xml,txt}'],
dest: 'bin/build/'
}, {
expand: true,
cwd: '.',
src: ['server/*.js', 'server/db.config.json'],
dest: 'bin/'
}]
},
debug: { // Target
files: [{
expand: true,
cwd: 'public',
src: ['**/*.{ttf,svg,eot,woff}', '**/*.{png,gif,jpg,jpeg,xml,txt}', '**/*.js'],
dest: 'bin/build/'
}, {
expand: true,
cwd: '.',
src: ['server/*.js', 'server/db.config.json'],
dest: 'bin/'
}]
}
},
jsdoc: {
default: {
src: ['**/*.js', '!node_modules/**', '!build/**', '!doc/**'],
options: {
destination: 'doc',
/* template: './node_modules/jsdoc-oblivion/template',
configure: './node_modules/jsdoc-oblivion/config/conf.json'
*/
}
}
},
csslint: {
strict: {
options: {
import: 2,
important: false
},
src: ['public/css/*.css']
},
lax: {
options: {
import: false,
important: false
},
src: ['public/css/*.css']
}
},
htmlhint: {
html1: {
options: {
'tagname-lowercase': true,
'attr-lowercase': true,
'attr-value-double-quotes': false,
'attr-value-not-empty': true,
'attr-no-duplication': true,
'doctype-first': false,
'tag-pair': true,
'tag-self-close': true,
'spec-char-escape': true,
'id-unique': true,
'src-not-empty': true,
'head-script-disabled': true,
'alt-require': true,
'doctype-html5': true,
'id-class-value': true,
'style-disabled': true,
'space-tab-mixed-disabled': true,
'id-class-ad-disabled': true,
'href-abs-or-rel': true,
'attr-unsafe-chars': true
},
src: ['public/**/*.html']
},
html2: {
options: {
'tag-pair': false
},
src: ['public/**/*.html']
}
},
targethtml: {
debug: {
files: {
'bin/build/index.html': 'public/index.html.tmpl'
}
},
release: {
files: {
'bin/build/index.html': 'public/index.html.tmpl'
}
}
},
htmlSnapshot: {
all: {
options: {
//that's the path where the snapshots should be placed
//it's empty by default which means they will go into the directory
//where your Gruntfile.js is placed
snapshotPath: 'bin/build/snapshots/',
//This should be either the base path to your index.html file
//or your base URL. Currently the task does not use it's own
//webserver. So if your site needs a webserver to be fully
//functional configure it here.
sitePath: 'http://localhost/',
//you can choose a prefix for your snapshots
//by default it's 'snapshot_'
fileNamePrefix: 'sp_',
//by default the task waits 500ms before fetching the html.
//this is to give the page enough time to to assemble itself.
//if your page needs more time, tweak here.
msWaitForPages: 1000,
//sanitize function to be used for filenames. Converts '#!/' to '_' as default
//has a filename argument, must have a return that is a sanitized string
sanitize: function (requestUri) {
//returns 'index.html' if the url is '/', otherwise a prefix
if (/\/$/.test(requestUri)) {
return 'index.html';
} else {
return requestUri.replace(/\//g, '-');
}
},
//if you would rather not keep the script tags in the html snapshots
//set `removeScripts` to true. It's false by default
removeScripts: true,
//set `removeLinkTags` to true. It's false by default
removeLinkTags: true,
//set `removeMetaTags` to true. It's false by default
removeMetaTags: true,
//Replace arbitrary parts of the html
replaceStrings: [{
'nothingbla': 'will get replaced by this'
}, {
'/old/path/': '/new/path'
}],
// allow to add a custom attribute to the body
bodyAttr: 'data-prerendered',
//here goes the list of all urls that should be fetched
urls: [
'',
'#/faq',
'#/home',
'#/help/info',
'#/help/when',
'#/help/address',
'#/help/show',
'#/privacy',
'#/booking',
'#/login',
'#/contact',
'#/cancel',
'#/cancel/confirm',
'#/cancel/other'
],
// a list of cookies to be put into the phantomjs cookies jar for the visited page
/* cookies: [{
"path": "/",
"domain": "localhost",
"name": "lang",
"value": "en-gb"
}],*/
// options for phantomJs' page object
// see http://phantomjs.org/api/webpage/ for available options
pageOptions: {
viewportSize: {
width: 1200,
height: 800
}
}
}
}
}
});
// Load the plugin that provides the tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-targethtml');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-html-snapshot');
grunt.loadNpmTasks('grunt-htmlhint');
// task(s).
grunt.registerTask('debug', ['clean:default', 'htmlmin:default', 'cssmin:default', 'copy:debug', 'targethtml:debug']);
grunt.registerTask('release', ['clean:release', 'jshint', 'uglify:release', 'imagemin', 'htmlmin:release', 'cssmin:release', 'copy:release', 'targethtml:release', 'htmlSnapshot']);
grunt.registerTask('default', ['clean:default', 'uglify:default', 'htmlmin:default', 'cssmin:default', 'imagemin', 'copy:release']);
grunt.registerTask('debug2', ['clean:default', 'cssmin:default', 'copy:debug']);
grunt.registerTask('doc', ['clean:doc', 'jsdoc']);
grunt.registerTask('css', ['csslint:lax']);
grunt.registerTask('html', ['htmlhint']);
grunt.registerTask('snapshot', ['htmlSnapshot']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment