0

The problem is in stream reloading page
Just reload method work correctly

But when I user browserSync.stream() (browserSync.reload({stream: true})) it's not working

It's my browser sync init function

function browserSyncInit(baseDir, browser) {
  browser = browser === undefined ? 'default' : browser;

  var routes = null;
  if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
    routes = {
      '/bower_components': 'bower_components'
    };
  }

  var server = {
    baseDir: baseDir,
    routes: routes,
    middleware: proxyMiddleware('http://0.0.0.0:8080')
  };

  var nodemonConfig = {
    cwd: path.normalize(__dirname + '/../../'),
    script: 'server/server.js',
    ext: 'js json',
    ignore: ['client/**/*.*'],
    env: {'PORT': '8080'}
  };
  var serverStarted;

  nodemon(nodemonConfig)
    .on('start', function () {
      if (serverStarted) return;

      browserSync.init(null, {
        startPath: '/',
        open: false,
        server: server,
        browser: browser
      });
      serverStarted = true;
    });
}

Proxy server it's Loopback application (may be problem in this)

It's task for reloading styles and scrips

gulp.task('styles-reload', ['styles'], function() {
  return buildStyles()
    .pipe(browserSync.stream());
});


gulp.task('scripts-reload', ['scripts'], function() {
  return buildScripts()
    .pipe(browserSync.stream());
});

1 Answers1

0

Streams are for injecting scripts/css/etc., from a task's Gulp stream, which is why in the documentation, it mentions to place it after the gulp.dest.

If you're looking to manually reload the BrowserSync page, you can do that with .reload in your two functions, otherwise, you'll need to pass through the files into your reload tasks, since it looks like you're calling those tasks from elsewhere.

To add to this, I don't see a reason to separate the two tasks (styles/scripts with their respective -reload tasks). You should just pipe it after the dest, so that you don't have to mess with starting a new stream or merging between tasks.

JSess
  • 638
  • 4
  • 13
  • thnx But in case changing styles, I want to stream it but I can't – Anton Barada Apr 25 '16 at 10:43
  • that's what I mention in the answer - "you'll need to pass through the files into your reload tasks, since it looks like you're calling those tasks from elsewhere." In other words, when you pipe browserSync.stream(), are the styles and scripts to be injected being returned from the buildScripts methods? – JSess Apr 25 '16 at 14:21