Skip to content

Instantly share code, notes, and snippets.

@mattbanks
Last active December 22, 2015 13:19
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 mattbanks/6478306 to your computer and use it in GitHub Desktop.
Save mattbanks/6478306 to your computer and use it in GitHub Desktop.
Grunt Setup with LESS
'use strict';
module.exports = function(grunt) {
// load all grunt tasks matching the `grunt-*` pattern
require('load-grunt-tasks')(grunt);
grunt.initConfig({
// watch for changes and trigger compass, jshint, uglify and livereload
watch: {
less: {
files: ['assets/less/**/*.less'],
tasks: ['less:development']
},
js: {
files: '<%= jshint.all %>',
tasks: ['jshint', 'uglify']
},
livereload: {
options: { livereload: true },
files: ['style.css', 'assets/js/*.js', '*.html', '*.php', 'assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}']
}
},
// less
less: {
development: {
options: {
paths: ["assets/css"]
},
files: {
"path/to/result.css": "path/to/source.less"
}
},
production: {
options: {
paths: ["assets/css"],
yuicompress: true
},
files: {
"path/to/result.css": "path/to/source.less"
}
}
}
// 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: {
plugins: {
options: {
sourceMap: 'assets/js/plugins.js.map',
sourceMappingURL: 'plugins.js.map',
sourceMapPrefix: 2
},
files: {
'assets/js/plugins.min.js': [
'assets/js/source/plugins.js',
// 'assets/js/vendor/yourplugin/yourplugin.js',
]
}
},
main: {
options: {
sourceMap: 'assets/js/main.js.map',
sourceMappingURL: 'main.js.map',
sourceMapPrefix: 2
},
files: {
'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/'
}]
}
},
});
// register task
grunt.registerTask('default', ['watch']);
grunt.resisterTask('build', 'less:production')
};
{
"name": "wordpress-starter-theme",
"version": "1.0.0",
"dependencies": {
"load-grunt-tasks": "~0.1.0"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-less": "~0.7.0",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.5.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment