Skip to content

Instantly share code, notes, and snippets.

@gilbitron gilbitron/Gruntfile.js
Last active Jan 4, 2016

Embed
What would you like to do?
Sample Gruntfile.js for Dunked.com
module.exports = function(grunt) {
// Config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
scripts: {
files: {
'assets/dist/dunked-scripts-before.min.js': [
// Our global JS goes here, things like jQuery, Backbone etc
]
}
},
styles: {
files: {
'assets/dist/dunked-styles.min.css': [
// Our global CSS goes here including our main style.css
]
}
}
},
jshint: {
options: {
reporter: require('jshint-stylish'),
'-W099': true // Ignore "Mixed spaces and tabs" warning
},
// App JS
dist: {
files: {
src: ['assets/scripts/app*.js']
}
},
// Template JS
templates: {
files: {
src: ['templates/**/lib.js']
}
},
// Front site JS
site: {
files: {
src: ['assets/site/scripts/lib.js']
}
}
},
uglify: {
dist: {
files: {
'assets/dist/dunked-scripts-before.min.js': 'assets/dist/dunked-scripts-before.min.js',
'assets/dist/dunked-scripts-after.min.js': 'assets/dist/dunked-scripts-after.min.js'
}
},
templates: {
files: [{
expand: true,
cwd: 'templates/',
src: ['**/lib.js'],
dest: 'templates/',
ext: '.min.js',
}]
},
site: {
files: {
'assets/site/scripts/lib.min.js': 'assets/site/scripts/lib.js'
}
}
},
sass: {
// App CSS
dist: {
options: {
style: 'expanded', // We use cssmin later to compress
cacheLocation: 'assets/dist/.sass-cache'
},
files: {
'assets/styles/style.css': 'assets/styles/style.scss',
// ...
}
},
// Site CSS
site: {
options: {
style: 'expanded', // We use cssmin later to compress
cacheLocation: 'assets/site/css/.sass-cache'
},
files: {
'assets/site/style.css': 'assets/site/css/style.scss'
}
}
},
csslint: {
options: {
csslintrc: '.csslintrc' // Separate CSSLint options file in root
},
dist: {
files: {
src: ['assets/styles/*.css', '!assets/styles/*.min.css'] // Don't lint .min.css files
}
},
site: {
options: {
"duplicate-properties": false // Override default setting
},
files: {
src: ['assets/site/**/*.css', '!assets/site/**/*.min.css'] // Don't lint .min.css files
}
}
},
autoprefixer: {
// App CSS
dist: {
files: {
'assets/dist/dunked-styles.min.css': 'assets/dist/dunked-styles.min.css'
}
},
// Site CSS
site: {
files: {
'assets/site/style.css': 'assets/site/style.css'
}
}
},
cssmin: {
options: {
keepSpecialComments: 1, // Keep 1st block comment
report: 'min' // Show some stats
},
// App CSS
dist: {
files: {
'assets/dist/dunked-styles.min.css': 'assets/dist/dunked-styles.min.css'
}
},
// Site CSS
site: {
files: {
'assets/site/style.min.css': 'assets/site/style.css'
}
}
},
// Note we split up our "watch" into sensible segments
watch: {
options: {
livereload: true
},
scripts: {
files: ['assets/scripts/**/*.js'],
tasks: ['concat:scripts', 'uglify:dist'],
options: {
spawn: false,
}
},
scss: {
files: ['assets/styles/**/*.scss'],
tasks: ['sass:dist', 'csslint:dist', 'concat:styles', 'autoprefixer:dist', 'cssmin:dist'],
options: {
spawn: false,
}
},
styles: {
files: ['assets/**/*.css', '!assets/styles/*.css'],
tasks: ['concat:styles', 'autoprefixer:dist', 'cssmin:dist'],
options: {
spawn: false,
}
},
templates: {
files: ['templates/**/lib.js'],
tasks: ['jshint:templates', 'uglify:templates'],
options: {
spawn: false,
}
},
jshint: {
files: ['assets/scripts/admin/*.js'],
tasks: ['jshint:dist'],
options: {
spawn: false,
}
},
site: {
files: ['assets/site/**/*css', 'assets/site/scripts/lib.js'],
tasks: [
'forceOn',
'jshint:site',
'forceOff',
'uglify:site',
'sass:site',
'forceOn',
'csslint:site',
'forceOff',
'autoprefixer:site',
'cssmin:site'
],
options: {
spawn: false,
}
}
}
});
// Plugins
require('load-grunt-tasks')(grunt);
// Setup tasks we can use to toggle --force (continue after warnings)
grunt.registerTask('forceOn', 'turns the --force option ON', function(){
if ( !grunt.option( 'force' ) ) {
grunt.config.set('forceStatus', true);
grunt.option( 'force', true );
}
});
grunt.registerTask('forceOff', 'turns the --force option OFF', function(){
if ( grunt.config.get('forceStatus') ) {
grunt.config.set('forceStatus', false);
grunt.option( 'force', false );
}
});
// Tasks for main app
grunt.registerTask('default', [
'concat:scripts',
'forceOn',
'jshint:dist',
'jshint:templates',
'forceOff',
'uglify:dist',
'uglify:templates',
'sass:dist',
'forceOn',
'csslint:dist',
'forceOff',
'concat:styles',
'autoprefixer:dist',
'cssmin:dist'
]);
// Tasks for front site
grunt.registerTask('site', [
'forceOn',
'jshint:site',
'forceOff',
'uglify:site',
'sass:site',
'forceOn',
'csslint:site',
'forceOff',
'autoprefixer:site',
'cssmin:site'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.