Skip to content

Instantly share code, notes, and snippets.

@r-k-b
Forked from robkb/gruntfile.js
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-k-b/2da43ffc23553ef8afd0 to your computer and use it in GitHub Desktop.
Save r-k-b/2da43ffc23553ef8afd0 to your computer and use it in GitHub Desktop.
improving the base gruntfile for fb-flo + less
/*
gruntfile based on https://gist.github.com/billyvg/2a7321623b2d2a87381c
[grab the associated `package.json` from here](https://gist.github.com/robert-bosweb/6c0303c11839f063b854)
*/
module.exports = function (grunt) {
var setup = {
pathToMainLessFile: "assets/less/", // include the trailing forward slash
mainLessFileName: "central" //.less is implied; leave it out
};
setup.mainLessFile = setup.pathToMainLessFile + setup.mainLessFileName;
grunt.initConfig({
config: setup,
less: {
main: {
options: {
sourceMap: true,
compress: true,
sourceMapFilename: '<%= config.mainLessFile %>.css.map',
sourceMapURL: '<%= config.mainLessFileName %>.css.map',
sourceMapRootpath: '/'
},
files: {
'<%= config.mainLessFile %>.min.css' : '<%= config.mainLessFile %>.less'
}
}
},
autoprefixer: {
options: {
map: true
},
main: {
src: '<%= config.mainLessFile %>.min.css',
dest: '<%= config.mainLessFile %>.min.prefixed.css'
}
},
watch:{
lessFiles :{
files: [
'**/*.less',
'!node_modules/**'
],
tasks: ['lessPrefixed'],
options: {}
}
},
concurrent: {
watchers: {
tasks: ['flo', 'watch'],
options: {
logConcurrentOutput: true
}
}
}
});
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-concurrent');
// configure your flo task
grunt.registerTask('flo', 'Runs the fb-flo server for live editing', function () {
var flo = require('fb-flo');
var path = require('path');
var fs = require('fs');
//noinspection JSUnusedLocalSymbols
var done = this.async();
var WEBROOT = process.cwd();
//noinspection JSUnusedLocalSymbols
var server = flo(
WEBROOT,
{
port: 8888,
host: 'localhost',
verbose: false,
persistent: true,
useFilePolling: false,
pollingInterval: 400,
globs: '**/*.css'
},
function (fp, callback) {
var excludefile = !!( fp.match(/___$/) || fp.match(/^\.idea/) || fp.match(/\.git/) );
if (!excludefile) {
console.log('fp: ' + fp);
callback({
resourceURL: '/' + fp,
contents: fs.readFileSync(WEBROOT + '/' + fp).toString()
/*reload : true*/
});
}
/*if (fp.match(/\.js$/)) {
callback({
resourceURL: fp.replace(/^web\/js/, '/js'),
contents : fs.readFileSync(WEB_ROOT + '/' + fp).toString(),
reload: true
});
}
else if (fp.match(/^build.*?\.css$/)) {
callback({
resourceURL: fp.replace(/^build\/web\/css/, '/css'),
contents : fs.readFileSync(WEB_ROOT + '/' + fp).toString(),
reload: true
});
}*/
}
);
});
grunt.registerTask('lessPrefixed', ['less:main', 'autoprefixer:main']);
grunt.registerTask('default', ['lessPrefixed', 'concurrent:watchers']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment