Skip to content

Instantly share code, notes, and snippets.

@Dilts
Last active August 29, 2015 14:25
Show Gist options
  • Save Dilts/15d53529b496ecb96f08 to your computer and use it in GitHub Desktop.
Save Dilts/15d53529b496ecb96f08 to your computer and use it in GitHub Desktop.
This is a grunt file that minimizes my JS and CSS as well as deploys to a staging server before production for Wordpress sites
'use strict';
module.exports = function(grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
// watch for changes and trigger compass, jshint, uglify and livereload
watch: {
options: {
livereload: true,
},
compass: {
files: ['assets/scss/**/*.{scss,sass}'],
tasks: ['compass']
},
js: {
files: '<%= jshint.all %>',
tasks: ['jshint', 'uglify']
},
livereload: {
files: ['*.html', '*.php', 'assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}']
}
},
// compass and scss
compass: {
dist: {
options: {
config: 'config.rb',
force: true
}
}
},
// javascript linting with jshint
jshint: {
options: {
jshintrc: '.jshintrc',
"force": true
},
all: [
'Gruntfile.js',
'assets/js/source/**/*.js'
]
},
// uglify to concat, minify, and make source maps
uglify: {
dist: {
options: {
sourceMap: 'assets/js/map/source-map.js'
},
files: {
'assets/js/plugins.min.js': [
'assets/js/source/plugins.js',
'assets/js/vendor/**/*.js',
'!assets/js/vendor/modernizr*.js'
],
'assets/js/main.min.js': [
'assets/js/source/main.js'
]
}
}
},
// image optimization
imagemin: {
dist: {
options: {
optimizationLevel: 7,
progressive: true
},
files: [{
expand: true,
cwd: 'assets/images/',
src: '**/*',
dest: 'assets/images/'
}]
}
},
// deploy via rsync
deploy: {
staging: {
src: "./",
dest: "~/path/to/theme",
host: "[email protected]",
recursive: true,
syncDest: true,
exclude: ['.git*', 'node_modules', '.sass-cache', 'Gruntfile.js', 'package.json', '.DS_Store', 'README.md', 'config.rb', '.jshintrc']
},
production: {
src: "./",
dest: "~/path/to/theme",
host: "[email protected]",
recursive: true,
syncDest: true,
exclude: '<%= rsync.staging.exclude %>'
}
}
});
// rename tasks
grunt.renameTask('rsync', 'deploy');
// register task
grunt.registerTask('default', ['watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment