node.js 如何在浏览器同步中配置端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30614962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:49:29  来源:igfitidea点击:

How to configure port in browser-sync

node.jsgulpbrowser-sync

提问by Gyanesh Gouraw

I have a gulptask 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.

我有一个gulp正在运行的任务browser-sync,默认情况下它在 node.js 服务器的端口 3000 上运行。我想将默认端口更改为任何其他端口,如 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 任务,如:

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

But it didnot work.

但它没有用。

回答by zaynetro

Answer based on the documentation links (link1, link2).

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

You are using browser-sync version 2.0+, they have a different recommended syntax. Using that syntax your code could be like this:

您使用的是浏览器同步版本 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
  });
});

You specify required port directly in configuration object.

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