Skip to content

Instantly share code, notes, and snippets.

@Bogdaan
Created March 1, 2015 16:20
Show Gist options
  • Save Bogdaan/93f5e7be85be899f8854 to your computer and use it in GitHub Desktop.
Save Bogdaan/93f5e7be85be899f8854 to your computer and use it in GitHub Desktop.
Gruntfile.js snippet
/**
* project minimalistic build template
*
* source - directory with source files
* source/img - standalone backgrounds or images for web
* source/icons - project icons (generate sprite)
* source/less - less project files
* source/css - css project files
* source/js - js project files
* source/lib - external libs, not from bower
* www - public web-root directory with build results and other files
* www/build/ - builder results (js, css, icons, images)
*
*/
module.exports = function(grunt)
{
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// validate files
jshint: {
files: ['Gruntfile.js', 'source/js/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
concat: {
lib: {
separator: ';',
src: [
'source/lib/**/*.js',
],
dest: 'www/build/vendor.js',
},
frontend: {
separator: ';',
src: ['source/js/frontend/*.js'],
dest: 'www/build/frontend.js',
},
admin: {
separator: ';',
src: [
'source/js/admin/*.js'
],
dest: 'www/build/admin.js',
},
//////////////////////////// MODULES HERE ////////////////////////////
},
uglify: {
options: {
banner: '/*! hcbogdan-build <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'www/build/vendor.min.js': ['www/build/vendor.js'],
'www/build/frontend.min.js': ['www/build/frontend.js'],
'www/build/admin.min.js': ['www/build/admin.js'],
}
}
}, // uglify
less: {
production: {
options: {
plugins: [
new (require('less-plugin-autoprefix'))({browsers: ["last 2 versions"]}),
new (require('less-plugin-clean-css'))
],
strictImports:true,
compress: true,
},
files: {
//////////////////////////// LESS RULES HERE ////////////////////////////
}
}
}, // less
imagemin: {
frontend: {
files: [{
expand: true,
cwd: 'source/img/',
src: ['**/*.{png,jpg,gif}'],
dest: 'www/build/img/'
}]
}
}, // imagemin
// OPTIONAL - publish vendor libs (custom files, images, css, backgrounds etc)
symlink: {
options: {
overwrite: false
},
explicit: {
src: 'source/lib',
dest: 'www/build/vendor'
},
},
cssmin: {
options: {
report: 'min',
root: 'www',
keepSpecialComments: 0,
},
/////////////////////////////////// MIN RULES HERE ///////////////////////////////////
}, // cssmin
sprite:{
all: {
src: 'source/icons/*.png',
dest: 'www/build/icons.png',
destCss: 'www/build/icons.css'
}
}, // sprite
watch: {
// autoreload
grunt: {
files: ['Gruntfile.js']
},
scripts: {
files: ['source/js/*', 'source/js/**/*.js'],
tasks: ['concat'],
options: {
// spawn: false,
},
},
less: {
files: [], //////////////////////////////// LESS FULES HERE
tasks: ['less'],
options: {
// spawn: false,
},
},
sprite: {
files: ['source/icons/*.png'],
tasks: ['sprite'],
options: {
// spawn: false,
},
},
images: {
files: ['source/img/*'],
tasks: ['imagemin'],
options: {
// spawn: false,
},
},
},
// watch
// CRITICAL PATH DETECTION
penthouse: {
extract : {
outfile: 'www/build/frontend.critical.css',
css: 'www/build/frontend.css',
url: 'http://HOST.local/', /////////////////////////////// HOST HERE ///////////////////////////////
width: 1300,
height: 900
},
},
notify_hooks: {
options: {
enabled: true,
max_jshint_notifications: 5,
title: 'project',
success: false,
duration: 3
}
},
notify: {
remoteredy: {
options: {
title: 'project',
message: 'build complate',
}
},
}, // notify
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-symlink');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-spritesmith');
// livereload - if needs
//grunt.loadNpmTasks('grunt-contrib-connect');
// not use
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// SUGAR
grunt.loadNpmTasks('grunt-penthouse');
grunt.loadNpmTasks('grunt-notify');
// development sync
//grunt.loadNpmTasks('grunt-rsync');
//grunt.loadNpmTasks('grunt-ssh');
//grunt.loadNpmTasks('grunt-shell');
////////////////////////////////////////////////////
grunt.registerTask('dev', ['less', 'concat']);
grunt.registerTask('minimal', ['less', 'concat', 'symlink', 'cssmin']);
grunt.registerTask('default', ['less', 'concat', 'symlink', 'cssmin']);
grunt.registerTask('full', ['less', 'concat', 'symlink', 'uglify', 'imagemin', 'sprite']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment