Fix gulp file reload

This commit is contained in:
Ruben van de Ven 2019-11-21 20:21:06 +01:00
parent 1d92fea37a
commit a0011ec660

View file

@ -15,6 +15,14 @@ var buffer = require('vinyl-buffer');
var through = require('through2')
// todo: rollup for d3 & possibly jsonld
const server = browserSync.create();
function reload(done) {
server.reload();
done();
}
var paths = {
"styles": {
"src": "./src/scss/*.scss",
@ -32,11 +40,12 @@ var paths = {
}
};
gulp.task('styles', function() {
gulp.src(paths.styles.src, { sourcemaps: true })
gulp.task('styles', function(done) {
// console.log(done);
return gulp.src(paths.styles.src, { sourcemaps: true })
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.reload({ stream: true }));
.pipe(server.reload({ stream: true }));
});
@ -55,6 +64,7 @@ gulp.task('scripts', function() {
// .pipe(sourcemaps.write('maps'))
.pipe(sourcemaps.write(''))
.pipe(gulp.dest(paths.scripts.d3destDir)) // save .min.js
// .pipe(server.reload())
});
gulp.task('d3', function() {
@ -84,22 +94,22 @@ gulp.task('jsonld', function(){
var watchStylesAndScripts = function() {
gulp.watch(paths.styles.src, gulp.series('styles'));
gulp.watch(paths.scripts.src,gulp.series('scripts', browserSync.reload));
gulp.watch(paths.scripts.d3src,gulp.series('d3', browserSync.reload));
gulp.watch([paths.data.src], gulp.series('jsonld', browserSync.reload));
gulp.watch(paths.scripts.src,gulp.series('scripts', reload));
gulp.watch(paths.scripts.d3src,gulp.series('d3', reload));
gulp.watch([paths.data.src], gulp.series('jsonld', reload));
}
gulp.task('watch', watchStylesAndScripts);
// watch files for changes and reload
gulp.task('serve', function() {
browserSync({
server.init({
server: {
baseDir: '.'
}
});
gulp.watch(['index.html','rubenvandeven.jsonld'], browserSync.reload({stream: true}));
gulp.watch(['index.html','rubenvandeven.jsonld'], reload);
watchStylesAndScripts();
});