Skip to content

Instantly share code, notes, and snippets.

@psi-4ward
Created December 19, 2013 11:25
Show Gist options
  • Save psi-4ward/8037802 to your computer and use it in GitHub Desktop.
Save psi-4ward/8037802 to your computer and use it in GitHub Desktop.
Grunt + LiveReload + LESS + Contao Be sure to have LiveReload Chrome Extension installed
var path = require('path');
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function(grunt) {
var dir = grunt.option('dir');
if(!dir) {
grunt.fail.fatal('Error: no watching directory specified! Use --dir option.', 1);
}
grunt.log.ok('Watching directory: ' + dir);
// load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
var cfg = {};
// On demand
cfg.watch = {
less: {
files: [dir + '/**/*.less'],
tasks: ['less']
},
css: {
files: [dir + '/**/*.css'],
options: {
livereload: true
}
}
};
// LESS
// running `grunt less` will compile once
cfg.less = {
dev: {
options: {
paths: [dir + "/**/*.less"],
yuicompress: false
},
files: {}
}
};
cfg.less.dev.files[dir + "/style.css"] = dir+"/less/style.less";
// init grunt with the config
grunt.initConfig(cfg);
// register server task
grunt.registerTask('default', [
// 'connect',
'watch'
]);
};
{
"name": "contao_livereload",
"version": "0.0.0",
"description": "Grunt based LiveReload for Contao",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-less": "~0.8.3",
"grunt-contrib-watch": "~0.5.3"
},
"author": "Christoph Wiechert",
"license": "GPL"
}
#!/bin/bash
GRUNTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR=$1
if [ "$DIR" == "" ]
then
DIR=.
fi
DIR=`realpath $DIR`
grunt --gruntfile $GRUNTDIR/Gruntfile.js --dir $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment