Skip to content

Instantly share code, notes, and snippets.

@jmacqueen
Last active December 27, 2015 02:39
Show Gist options
  • Save jmacqueen/7253789 to your computer and use it in GitHub Desktop.
Save jmacqueen/7253789 to your computer and use it in GitHub Desktop.
Basic Grunt config for working with the Bones Wordpress starter theme

A basic Grunt configuration for working with the Bones Wordpress Starter theme. To be expanded! Compiles and compresses Sass and uses rsync to update the local installation of Wordpress for testing so I can keep my MAMP installation free of extraneous files...and simply FTP over the final result if it checks out without putting uneccessary node_modules or .scss files on the server by mistake. This was pretty much put together because I kept mistakenly FTPing over my .sass-cache files like an idiot.

For this to work, the theme in development lives in 'src' inside the project directory so node_modules, .sass-cache, gruntfile.js, package.json and src are all together in the top-level directory.

project folder
  .sass-cache
  gruntfile.js
  node_modules
  package.json
  src
module.exports = function(grunt) {
require("matchdep").filterDev("grunt-*", './package.json').forEach(grunt.loadNpmTasks);
var globalConfig = {
src: 'src',
dest: '/path-to-local-Wordpress-installation/wp-content/themes/new-theme-name/'
};
grunt.initConfig({
globalConfig: globalConfig,
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: ['<%= globalConfig.src %>/library/scss/*.scss'],
tasks: ['buildcss']
},
php: {
files: ['<%= globalConfig.src %>/**/*.php'],
tasks: ['buildphp']
},
js: {
files: ['<%= globalConfig.src %>/**/*.php'],
tasks: ['buildjs']
},
images: {
files: ['<%= globalConfig.src %>/**/*.jpg','<%= globalConfig.src %>/**/*.png','<%= globalConfig.src %>/**/*.gif'],
tasks: ['buildimages']
}
},
sass: {
build: {
options: {
trace: true,
style: 'compressed'
},
files: [{
expand: true,
cwd: '<%= globalConfig.src %>/library/scss/',
src: ['*.scss','!_*'],
dest: '<%= globalConfig.src %>/library/css/',
ext: '.css'
}]
}
},
rsync: {
options: {
args: ["--verbose"],
exclude: [".git*","scss",".DS_Store"],
recursive: true,
syncDest: true
},
build: {
options: {
src: "./<%= globalConfig.src %>/",
dest: "<%= globalConfig.dest %>"
}
}
}
}); // End initConfig
grunt.registerTask('default',['watch']);
grunt.registerTask('buildcss', ['sass','rsync']);
grunt.registerTask('buildphp', ['rsync']);
grunt.registerTask('buildjs', ['rsync']);
grunt.registerTask('buildimages', ['rsync']);
};
{
"name": "bones-based-theme",
"version": "0.1.0",
"description": "Theme description",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"author": "",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-sass": "~0.5.0",
"grunt-contrib-cssmin": "~0.6.2",
"matchdep": "~0.3.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-rsync": "~0.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment