Created
March 26, 2017 15:25
-
-
Save absent1706/99e846dba9cb30c22cc0958d1011995b to your computer and use it in GitHub Desktop.
knowstory-gulpfile-livereload
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
var gulp = require('gulp'); | |
var less = require('gulp-less'); | |
var watch = require('gulp-watch'); | |
// var util = require("gulp-util"); | |
const notifier = require('node-notifier'); | |
var path = require('path'); | |
var combiner = require('stream-combiner2'); | |
var browserSync = require('browser-sync').create(); | |
gulp.task('_less', function(){ | |
var combined = combiner.obj([ | |
gulp.src('app/css/*.less'), | |
less(), | |
gulp.dest('app/css/'), | |
browserSync.stream() | |
]); | |
combined.on('error',function(e){ | |
notifier.notify({ | |
title: 'Less error', | |
message: e.message, | |
sound: false, | |
time: 2000, | |
icon: path.join(__dirname, 'design_dev_scripts', 'error.png'), | |
}) | |
}); | |
return combined; | |
}); | |
gulp.task('less', [ '_less' ], function () { | |
notifier.notify({ | |
title: 'Less compiled', | |
"message": "less compiled successfully!", | |
"sound": false, | |
time: 1000, | |
icon: path.join(__dirname, 'design_dev_scripts', 'success.png'), | |
}); | |
}); | |
gulp.task('livereload', function() { | |
gulp.watch("**/*.html").on("change", browserSync.reload); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch('app/css/*.less', ['less']); | |
}); | |
/* see https://webref.ru/dev/automate-with-gulp/live-reloading */ | |
gulp.task('browserSync', function() { | |
browserSync.init({ | |
// server: { | |
// baseDir: "./" | |
// }, | |
// open: true, | |
proxy: "127.0.0.1:8080" | |
}); | |
}); | |
gulp.task('default', [ 'less' ]); | |
gulp.task('serve', [ 'less', 'browserSync', 'watch', 'livereload' ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment