Skip to content

Instantly share code, notes, and snippets.

@pudgereyem
Created February 6, 2014 20:58
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 pudgereyem/8852350 to your computer and use it in GitHub Desktop.
Save pudgereyem/8852350 to your computer and use it in GitHub Desktop.
GRUNT: My Grunt Setup
/*
TO DO
1) Reduce CSS duplication
- Ideally just a single build - global.scss turns into /build/global.css
- Can Autoprefixer output minified?
- If it can, is it as good as cssmin?
- Could Sass be used again to minify instead?
- If it can, is it as good as cssmin?
2) Better JS dependency management
- Require js?
- Can it be like the Asset Pipeline where you just do //= require "whatever.js"
3) Is HTML minification worth it?
4) Set up a Jasmine test just to try it.
5) Can this Gruntfile.js be abstracted into smaller parts?
- https://github.com/cowboy/wesbos/commit/5a2980a7818957cbaeedcd7552af9ce54e05e3fb
*/
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
// cssmin will minify later
style: 'expanded'
},
files: {
'css/build/global.css': 'css/global.scss'
}
}
},
autoprefixer: {
options: {
browsers: ['last 2 version']
},
multiple_files: {
expand: true,
flatten: true,
src: 'css/build/*.css',
dest: 'css/build/prefixed/'
}
},
cssmin: {
combine: {
files: {
'css/build/minified/global.css': ['css/build/prefixed/global.css']
}
}
},
jshint: {
beforeconcat: ['js/*.js']
},
concat: {
dist: {
src: [
'js/libs/*.js',
'js/global.js'
],
dest: 'js/build/production.js'
}
},
uglify: {
build: {
src: 'js/build/production.js',
dest: 'js/build/production.min.js'
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'images/',
src: ['**/*.{png,jpg,gif}'],
dest: 'images/'
}]
}
},
watch: {
options: {
livereload: true,
},
scripts: {
files: ['js/*.js'],
tasks: ['jshint', 'concat', 'uglify'],
options: {
spawn: false,
}
},
css: {
files: ['css/*.scss'],
tasks: ['sass', 'autoprefixer', 'cssmin'],
options: {
spawn: false,
}
},
images: {
files: ['images/**/*.{png,jpg,gif}', 'images/*.{png,jpg,gif}'],
tasks: ['imagemin'],
options: {
spawn: false,
}
}
},
connect: {
server: {
options: {
port: 8000,
base: './'
}
}
},
});
require('load-grunt-tasks')(grunt);
// Default Task is basically a rebuild
grunt.registerTask('default', ['concat', 'uglify', 'sass', 'imagemin']);
grunt.registerTask('dev', ['connect', 'watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment