13

I have a gulp task running with browser-sync,by default its running on port 3000 of node.js server.I want to change the default port to any other port like 3010.

    var gulp = require('gulp'), 
    connect = require('gulp-connect'),          
    browserSync = require('browser-sync');    

    gulp.task('serve', [], function() {
    browserSync(
      {
        server: "../ProviderPortal"
       });
   });
   /*** 8. GULP TASKS **********/
   gulp.task('default', ['serve']);

I am using:

browser-sync version-2.6.1

I tried configuring the gulp task like:

gulp.task('serve', [], function() {
    browserSync(
    {
        ui: {
       port: 8080
       },
        server: "../ProviderPortal"
    });
});

But it didnot work.

4

1 回答 1

41

根据文档链接(link1link2)回答。

您使用的是浏览器同步版本 2.0+,它们有不同的推荐语法。使用该语法,您的代码可能是这样的:

// require the module as normal
var bs = require("browser-sync").create();

....

gulp.task('serve', [], function() {
  // .init starts the server
  bs.init({
    server: "./app",
    port: 3010
  });
});

您直接在配置对象中指定所需的端口。

于 2015-06-03T09:08:39.450 回答