Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails, Gulp, and Browsersync together at last
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var setupWatchers = function() {
gulp.watch(['./app/views/**/*.erb',
'./app/assets/javascripts/**/*.js'], ['reload']);
gulp.watch(['./app/assets/stylesheets/**/*.scss'], ['reloadCSS'])
};
gulp.task('reload', function(){
return browserSync.reload();
});
gulp.task('reloadCSS', function() {
return browserSync.reload('*.css');
});
gulp.task('init', function() {
browserSync.init({
proxy: 'localhost:7999',
port: 8000,
open: false,
ui: {
port: 8001
}
});
setupWatchers();
});
gulp.task('default', ['init']);
@jonathan-soifer

This comment has been minimized.

Copy link

@jonathan-soifer jonathan-soifer commented Mar 12, 2016

Can't get this to work :(
Everything runs apparently fine...

[18:36:18] Using gulpfile ~/GitHub/analytiks.ninja/gulpfile.js
[18:36:18] Starting 'init'...
[18:36:18] Finished 'init' after 48 ms
[18:36:18] Starting 'default'...
[18:36:18] Finished 'default' after 36 μs
[BS] [info] Proxying: http://localhost:3000
[BS] Access URLs:
 ------------------------------------
       Local: http://localhost:8000
    External: http://192.168.0.2:8000
 ------------------------------------
          UI: http://localhost:8001
 UI External: http://192.168.0.2:8001

Rails server is running on :3000 and it works ok. But when trying to access :8000 nothing shows up (forever loading).
:8001 shows up ok

@bsodmike

This comment has been minimized.

Copy link

@bsodmike bsodmike commented Apr 21, 2016

Same here @wnstn, no luck.

@bsodmike

This comment has been minimized.

Copy link

@bsodmike bsodmike commented Apr 21, 2016

Success! @jonathan-soifer Just start your local rails server whilst binding to 0.0.0.0 using rails s -b 0.0.0.0. I also set the proxy port as 8080.

@wnstn

This comment has been minimized.

Copy link
Owner Author

@wnstn wnstn commented Apr 21, 2016

@bsodmike @jonathan-soifer so sorry, i didn't see notifications here. If you're running on default rails port change this block to this:

gulp.task('init', function() {
  browserSync.init({
      proxy: 'localhost:3000',
      port: 3001,
      open: false,
      ui: {
        port: 3002
      }
  });

and then you can access browsersync at localhost:3001

@bsodmike

This comment has been minimized.

Copy link

@bsodmike bsodmike commented Apr 21, 2016

Hey @wnstn the original port config was fine, all I needed to do was bind my rails server. I found that it would sometimes (locally) jump to ipv6, but binding seems to take care of that.

+gulp.task('init', function() {
+  browserSync.init({
+    proxy: '0.0.0.0:3000',
+    port: 8000,
+    open: false,
+    ui: {
+      port: 8001
+    }
+  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment