Skip to content

Instantly share code, notes, and snippets.

@hearsid
Created February 28, 2016 16:45
Show Gist options
  • Save hearsid/ce2cae08f359bd2ab902 to your computer and use it in GitHub Desktop.
Save hearsid/ce2cae08f359bd2ab902 to your computer and use it in GitHub Desktop.
File to watch and compile less files in (./css) folder and compile es6 file using babel in (./js/*/*-es6.js) folder with mentioned ending letters . On starting the script the files are compiled once . You can also individually compile just less or es6 files .
// Automate front end processes
// TODO
// 1) use npm plugin angular template cache to generate cache of either the html or the jsp files
var less = require('gulp-less');
var path = require('path');
var gulp = require('gulp');
var minifyCSS = require('gulp-minify-css');
var watch = require('gulp-watch');
var babel = require('gulp-babel');
gulp.task('watch-less-es6', function () {
watchLess() ;
// whenever any file in the js folder or direct subfolder of js having -es6.js in its name
watchES6() ;
});
// just watch the less files
function watchLess() {
watch('./css/*.less', function () {
complileLessFile();
});
}
// just watch the es6 files
gulp.task('watch-es6' , function() {
watchES6() ;
})
function watchES6() {
watch( './js/*/*-es6.js' , function() {
compileES6() ;
});
}
function compileES6() {
return gulp.src(['./js/*-es6.js' , './js/*/*-es6.js'] , { base : './'})
.pipe( babel({
presets : ['es2015']
}))
.pipe(gulp.dest('./js/compiled'));
}
function complileLessFile() {
gulp.src('./css/*.less')
.pipe(less())
.pipe(minifyCSS())
.pipe(gulp.dest('./css/compiled/'));
}
// compile the less file once on start of the command
complileLessFile();
compileES6() ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment