question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BrowserSync not starting when watch: true

See original GitHub issue

If I have watch: true enabled in the webpack config, BrowserSync won’t start for some reason. Note, I don’t have watching enabled in gulp.

JS task:

gulp.task('js', () => {
  return gulp.src('')
    .pipe(plumber())
    .pipe(webpack(webpackConfig))
    .on('error', notify.onError({
      message: (error) => {
        return error.message;
      }
    }))
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(through.obj(function (file, enc, cb) {
      var isSourceMap = /\.map$/.test(file.path);
      if (!isSourceMap) this.push(file);
      cb();
    }))
    .pipe(gulp.dest('valamar/static/js/dist/'))
    .on('end', reload);
});

Default gulp task:

gulp.task('default', ['sass', 'js'], () => {
  browserSync.init({
    proxy: 'localhost:8000',
    ghostMode: false,
    notify: false,
    open: false,
    ui: false

Webpack config:

  watch: true,
  devtool: 'source-map',
  resolve: {
    modulesDirectories: ['node_modules', dir_js]
  },
  entry: {
    vendor: ['jquery'],
    app: path.resolve(dir_js, 'app/app.js'),
    admin: path.resolve(dir_js, 'admin/admin.js')
  },
  output: {
    path: dir_build,
    filename: '[name].js'
  },
  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /(node_modules|vendor)/,
      loader: 'babel-loader'
    }]
  },
  plugins: [
    // new webpack.optimize.DedupePlugin(),
    new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
  ]

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
dsiffordcommented, Aug 28, 2016

@zaqqaz A complete example would be lovely.

2reactions
zaqqazcommented, May 31, 2016

Just, add handler, and trigger brwser sync from them. Something like that:

....

let webpackChangeHandler = function (err, stats) {
        $.util.log(stats.toString({
            colors: $.util.colors.supportsColor,
            chunks: false,
            hash: false,
            version: false
        }));

        browserSync.reload();

        firstBuildReady = true;
    };

....

    return  gulp.src('')
        .pipe(plumber({errorHandler: conf.errorHandler('webpack-stream')}))
        .pipe(webpackStream(webpackOptions, null, webpackChangeHandler))
        .pipe(gulp.dest('valamar/static/js/dist/'))
        .on('data', () => {
            if (firstBuildReady && callback) callback()
        });
Read more comments on GitHub >

github_iconTop Results From Across the Web

BrowserSync Not Loading - Stack Overflow
BrowserSync looks for an 'index.html' file to start up and we get the ... watch: true, // <-- Adding this line solved my...
Read more >
Browsersync options
Browsersync makes your browser testing workflow faster by synchronising URLs, interactions and code changes across multiple devices.
Read more >
BrowserSync keeps reloading infinitely upon JavaScript ...
It was working fine, when I started editing an already existing scss file. Make my changes, save the file and got linter errors,...
Read more >
Quick setup for Gulp 4 + Browsersync + Sass - Coder Coder
How to make Browsersync work in your Gulp 4 workflow, with code examples and ... the Browsersync server, and finally running our watch...
Read more >
BrowserSync/Live-Server not updating in Gulp File
p>**Expected behavior** BrowserSync/Live Server to reflect all changes made in SaSS, CSS, or JS files.</p> <p>**Actual behavior** Will get stuck on a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found