-
-
Save r-k-b/2da43ffc23553ef8afd0 to your computer and use it in GitHub Desktop.
improving the base gruntfile for fb-flo + less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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