Skip to content

Instantly share code, notes, and snippets.

@micahredding
Last active December 31, 2015 01:29
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 micahredding/7914834 to your computer and use it in GitHub Desktop.
Save micahredding/7914834 to your computer and use it in GitHub Desktop.
Gruntfile, with package.json. Handles sass, coffeescript, and image optimization. You should probably add .sass-cache and node_modules to .gitignore.
1. Put these two files (Gruntfile.js and package.json) into your theme directory.
2. cd into the theme directory.
3. npm install
4. grunt
This assumes:
1. You have an app.scss file in assets/scss/app.scss, and that it compiles to assets/css/app.css
2. You have an app.coffee file in assets/coffee/app.coffee, and that it compiles to assets/js/app.js
3. You have images in assets/images - they will be optimized
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
sass: {
files: ['assets/scss/**/*.{scss,sass}','assets/scss/_partials/**/*.{scss,sass}'],
tasks: ['sass:dist']
},
coffee: {
files: ['assets/coffee/*.coffee'],
tasks: 'coffee'
},
livereload: {
files: ['*.html', '*.php', 'assets/js/**/*.{js,json}', 'assets/css/*.css','assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}'],
options: {
livereload: true
}
}
},
sass: {
dist: {
files: {
'assets/css/app.css': 'assets/scss/app.scss'
}
}
},
coffee: {
compile: {
files: {
'assets/js/app.js': 'assets/coffee/app.coffee'
}
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'assets/images',
src: ['**/*.{png,jpg,gif}'],
dest: 'assets/images'
}]
}
}
});
grunt.registerTask('default', ['sass:dist', 'coffee', 'imagemin', 'watch']);
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-watch');
};
{
"name": "Drupal",
"version": "1.0.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-sass": "~0.5.1",
"grunt-contrib-coffee": "~0.8.0",
"grunt-contrib-imagemin": "~0.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment