Skip to content

Instantly share code, notes, and snippets.

@stikoo
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stikoo/8913413 to your computer and use it in GitHub Desktop.
Save stikoo/8913413 to your computer and use it in GitHub Desktop.
My Gruntfile.js
module.exports = function(grunt) {
// store a var to the process cwd (current working directory)
var cwd = process.cwd();
// use the time plugin for build completion time
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
dirs: {
src: 'www/addons/shared_addons/themes/stikoo/src',
dist: 'www/addons/shared_addons/themes/stikoo/build',
ops: 'front-end-ops'
},
// watch uses the cwd var to initiate the watch tasks
watch: {
options: {
cliArgs: ['--gruntfile', require('path').join(cwd, 'Gruntfile.js')],
},
css: {
files: [
'<%= dirs.src %>/sass/**/*.scss',
],
tasks: ['compass']
},
js: {
files: [
'<%= dirs.src %>/js/polyfill/*.js',
'<%= dirs.src %>/js/libs/*.js',
'<%= dirs.src %>/js/script.js',
'<%= dirs.ops %>/Gruntfile.js',
'!**/node_modules/**'
],
tasks: ['jshint', 'concat:dev']
},
img: {
files: [
'<%= dirs.src %>/img/*',
],
tasks: ['copy:img']
}
},
clean: ['<%= dirs.dist %>'],
copy: {
img: {
cwd: '<%= dirs.src %>/img/',
expand: true,
src: '*',
dest: '<%= dirs.dist %>/img/',
filter: 'isFile'
},
},
compass: {
dev: {
options: {
httpPath: "www/",
cssPath: "<%= dirs.dist %>/css",
sassPath: "<%= dirs.src %>/sass",
imagesPath: "<%= dirs.src %>/img",
javascriptsPath: "<%= dirs.src %>/js",
cacheDir: '<%= dirs.ops %>/.sass-cache'
}
}
},
cssmin: {
add_banner: {
options: {
banner: '/*! <%= pkg.name %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> */'
},
files: {
'<%= dirs.dist %>/css/style.css': ['<%= dirs.dist %>/css/style.css']
}
}
},
jshint: {
files: ['<%= dirs.ops %>/Gruntfile.js', '<%= dirs.src %>/js/script.js'],
options: {
"strict": false,
"globals": {
"jQuery": true,
"console": true
}
},
},
// concat without minification on dev
concat: {
options: {
stripBanners: true,
banner: '/*! <%= pkg.name %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> */'
},
dev: {
files: {
'<%= dirs.dist %>/js/polyfill.js': ['<%= dirs.src %>/js/polyfill/respond.js', '<%= dirs.src %>/js/polyfill/html5shiv.js'],
'<%= dirs.dist %>/js/script.js': ['<%= dirs.src %>/js/libs/modernizr.js', '<%= dirs.src %>/js/libs/jquery.js', '<%= dirs.src %>/js/script.js'],
}
}
},
// concat with minification on dist
uglify: {
options: {
banner: '/*! <%= pkg.name %> - ' + '<%= grunt.template.today("dd-mm-yyyy") %> */',
mangle: false
},
dist: {
files: {
'<%= dirs.dist %>/js/polyfill.js': ['<%= dirs.src %>/js/polyfill/respond.js', '<%= dirs.src %>/js/polyfill/html5shiv.js'],
'<%= dirs.dist %>/js/script.js': ['<%= dirs.src %>/js/libs/modernizr.js', '<%= dirs.src %>/js/libs/jquery.js', '<%= dirs.src %>/js/script.js'],
}
}
},
imagemin: { // Task
dynamic: { // Another target
files: [{
expand: true, // Enable dynamic expansion
cwd: '<%= dirs.src %>/img/', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: '<%= dirs.dist %>/img/' // Destination path prefix
}]
}
}
});
// Register the tasks.
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
// I have grunt in a sub-directory, so to avoid problems with some
// grunt tasks, we instruct grunt to run from the root directory
// this is why we also have to pass the watch task a path to the grunt file
grunt.file.setBase('../');
// default tasks
grunt.registerTask('default', ['clean', 'compass', 'concat', 'copy:img', 'watch']);
// build development version
grunt.registerTask('build:dev', ['clean', 'compass', 'concat', 'jshint', 'copy:img']);
// build distribution version
grunt.registerTask('build:dist', ['clean', 'compass', 'cssmin', 'jshint', 'uglify', 'imagemin']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment