browserSync + gulp

1

I am planning a project in MEAN and I can hardly find the angle part.

I want to do everything from scratch to learn about gulp and its functionality as well as other tools, however, I ran into the following problem:

When I use the browser-sync it just does not work. I open the browser as I want and if I open the correct files, but does not update the browser when I ask.

Structure of folders and files

gulpfile.babel.js

import gulp         from "gulp";
import browserify   from "browserify";
import source       from "vinyl-source-stream";
import htmlmin      from "gulp-htmlmin";
import streamify    from "gulp-streamify";
import uglify       from "gulp-uglify";
let browserSync = require("browser-sync").create();

gulp.task("default", ["serve"]);

gulp.task("move-html", () => {
  return gulp.src("index.html")
    .pipe(htmlmin({collapseWhitespace: true}))
    .pipe(gulp.dest("dist"));
});

gulp.task("transpile", ["move-html"], () => {
  return browserify("src/app.js")
    .transform("babelify")
    .bundle()
    .on("error", function(error){
      console.error( "\nError: ", error.message, "\n");
      this.emit("end");
    }).pipe(source("bundle.js"))
    .pipe(streamify(uglify()))
    .pipe(gulp.dest("dist"));
});

gulp.task("reload", ["transpile"], () => {
  browserSync.reload();
  done();
});

gulp.task("serve", () => {
  browserSync.init({
    server: {
      baseDir: "dist"
    }
  });
  gulp.watch("client/**/*", ["reload"]);
});

I have reviewed and followed several tutorials but none of them work for me, when I execute the task serve command (which appears in my gulpfile) the following output appears:

However, when I update my files, the browser reload is not done.

    
asked by javierojeda 25.11.2016 в 08:14
source

1 answer

2

I already solved the problem. It turns out that in my function

gulp.watch("client/**/*.js", ["reload"])

A folder that does not exist is being searched. Just remove the client of the blob and you're done.

Now my browsersync works correctly.

    
answered by 25.11.2016 / 08:33
source