Skip to content

Instantly share code, notes, and snippets.

@ethyde
Last active August 29, 2015 14:07
Show Gist options
  • Save ethyde/7bf4a3217bd851ee3bff to your computer and use it in GitHub Desktop.
Save ethyde/7bf4a3217bd851ee3bff to your computer and use it in GitHub Desktop.
Grunt base config
/**
* @fileOverview Gruntfile tasks. These tasks are intended to help you when modifying the template. If you are
* just using the template, don't sweat this stuff. To use these tasks, you must install grunt, if you haven't already,
* and install the dependencies. All of this requires node.js, of course.
*
* Install grunt:
*
* npm install -g grunt-cli
*
* Then in the directory where you found this file:
*
* npm install
*
* And you are all set. See the individual tasks for details.
*
* @module Gruntfile
* @requires load-grunt-tasks
*/
module.exports = function( grunt ) {
'use strict';
require( 'time-grunt' )( grunt );
// load all task listed and speed up build process
require( 'jit-grunt' )( grunt );
// Project configuration.
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
meta: {
day: '<%= grunt.template.today("dd-mm-yyyy") %>',
hour: '<%= grunt.template.today("HH:MM") %>',
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= meta.day %> <%= meta.hour %> */\n',
dev: {
assets: 'dev',
less: '<%= meta.dev.assets %>/less',
js: '<%= meta.dev.assets %>/js',
img: '<%= meta.dev.assets %>/images',
fonts: '<%= meta.dev.assets %>/fonts'
},
prod: {
assets: 'dist',
css: '<%= meta.prod.assets %>/css',
js: '<%= meta.prod.assets %>/js',
img: '<%= meta.prod.assets %>/images',
fonts: '<%= meta.prod.assets %>/fonts'
}
},
// A list of files, which will be syntax-checked by JSHint with some options https://gist.github.com/haschek/2595796
jshint: {
options: {
funcscope: true, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
curly: true, // Require {} for every new block or scope.
eqeqeq: true, // Require triple equals i.e. `===` or !==.
immed: true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
latedef: true, // Prohibit variable use before definition.
newcap: true, // Require capitalization of all constructor functions e.g. `new F()`.
noarg: true, // Prohibit use of `arguments.caller` and `arguments.callee`.
sub: true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
undef: true, // Require all non-global variables be declared before they are used.
eqnull: true, // Tolerate use of `== null`.
browser: true, // Standard browser globals e.g. `window`, `document`.
unused: false, // Warns when you define and never use your variables.
jquery: true, // Enable globals ($ or jQuery) exposed by jQuery JavaScript library.
devel: true, // Allow development statements e.g. `console.log();`, TODO : Set to false before production
globals: { // define custom global here like Modernizr
Modernizr: true // Enable globals exposed by Modernizr library.
}
},
files: [ 'Gruntfile.js', '<%= concat.dev.dest %>' ]
},
// clean files assets in folders
clean: {
assets: [ '<%= meta.prod.css %>/',
'<%= meta.prod.js %>/*.*',
'<%= meta.prod.img %>/',
'<%= meta.prod.fonts %>/'
]
},
// Copy files and folders.
copy: {
font: {
expand: true, // Enable dynamic expansion
cwd: '<%= meta.dev.fonts %>/', // Src matches are relative to this path
src: [ '*.{eot,svg,ttf,otf,woff}' ], // Actual patterns to match
dest: '<%= meta.prod.fonts %>/' // Destination path prefix
},
jsvendor: {
expand: true,
cwd: '<%= meta.dev.js %>/vendor/',
src: [ '*.js' ],
dest: '<%= meta.prod.js %>/vendor/'
}
},
// Concat JS files
concat: {
options: {
banner: '<%= meta.banner %>',
sourceMap: true
},
dev: {
src: [ '<%= meta.dev.js %>/plugins.js',
'<%= meta.dev.js %>/plugins/*.js',
'<%= meta.dev.js %>/main.js'
],
dest: '<%= meta.prod.js %>/main.js'
}
},
// Minify your JS files
uglify: {
options: {
banner: '<%= meta.banner %>'
},
prod: {
src: '<%= concat.dev.src %>',
dest: '<%= meta.prod.js %>/main.js'
}
},
// Grunt contrib less task
less: {
options: {
banner: '<%= meta.banner %>'
},
dev: {
options: {
sourceMap: true
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
},
prod: {
options: {
plugins: [
new( require( 'less-plugin-clean-css' ) )( {
'advanced': true,
'compatibility': "ie8"
} )
],
},
src: '<%= meta.dev.less %>/main.less',
dest: '<%= meta.prod.css %>/main.css'
}
},
// Minify PNG, JPEG and GIF images
imagemin: {
opti: {
files: [ {
expand: true,
cwd: '<%= meta.dev.img %>/',
src: [ '**/*.{png,jpg,gif}' ],
dest: '<%= meta.prod.img %>/'
} ]
}
},
// Watch and livereload
watch: {
options: {
livereload: 6325
},
js: {
files: [ '<%= meta.dev.js %>/main.js', '<%= meta.dev.js %>/plugins/*.js' ],
tasks: [ 'concat' ]
},
images: {
files: '<%= meta.dev.img %>/**/*.{png,jpg,gif}',
tasks: [ 'imagemin' ]
},
css: {
files: '<%= meta.dev.less %>/**/*.less',
tasks: [ 'less:dev' ]
},
views: {
files: 'application/views/scripts/**/*.phtml'
}
}
} );
// This is the default task being executed if Grunt
// is called without any further parameter.
grunt.registerTask( 'default', [ 'less:dev', 'concat', 'imagemin', 'copy', 'watch' ] );
grunt.registerTask( 'prod', [ 'clean', 'less:prod', 'concat', 'uglify', 'imagemin', 'copy' ] );
};
{
"name": "project_name",
"version": "0.1.0",
"description": "Development setup",
"author": "auteur",
"private": true,
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-copy": "~0.8.0",
"grunt-contrib-imagemin": "~0.9.4",
"grunt-contrib-jshint": "~0.11.2",
"grunt-contrib-less": "~1.0.0",
"grunt-contrib-uglify": "~0.9.1",
"grunt-contrib-watch": "0.6.1",
"jit-grunt": "~0.9.1",
"less-plugin-clean-css": "^1.5.0",
"time-grunt": "^1.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment