admin管理员组

文章数量:1242825

I want to try using gulp and I've made a simple project similar to this example
what I want to do is to serve the project using different port, I've tried to follow this costum-port example

and my gulpfile.js looks like this :

var gulp = require('gulp');
var browserSync = require('browser-sync');
var livereload = require('gulp-livereload');
var reload = browserSync.reload;

// watch files for changes and reload
gulp.task('serve', function() {
  livereload.listen(1234);

  browserSync({
    server: {
      baseDir: 'app',
    }
  });

  gulp.watch(['*.html', 'styles/**/*.css', 'scripts/**/*.js'], {cwd: 'app'}, reload);
});

I also try to add port in server :{porrt : 9999, baseDir:'app'} but the result end up with the default port which is 3000.

Is it possible to change the port? Thanks.

I want to try using gulp and I've made a simple project similar to this example
what I want to do is to serve the project using different port, I've tried to follow this costum-port example

and my gulpfile.js looks like this :

var gulp = require('gulp');
var browserSync = require('browser-sync');
var livereload = require('gulp-livereload');
var reload = browserSync.reload;

// watch files for changes and reload
gulp.task('serve', function() {
  livereload.listen(1234);

  browserSync({
    server: {
      baseDir: 'app',
    }
  });

  gulp.watch(['*.html', 'styles/**/*.css', 'scripts/**/*.js'], {cwd: 'app'}, reload);
});

I also try to add port in server :{porrt : 9999, baseDir:'app'} but the result end up with the default port which is 3000.

Is it possible to change the port? Thanks.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 30, 2016 at 3:29 Gujarat SantanaGujarat Santana 10.6k17 gold badges55 silver badges75 bronze badges 4
  • Why do you use both browser-sync and gulp-livereload? – qtuan Commented Apr 30, 2016 at 3:54
  • Hmm still new here, I thought gulp-livereload will change the port ? so I use that. – Gujarat Santana Commented Apr 30, 2016 at 3:58
  • 2 You mean BrowserSync different port – Ben Racicot Commented Apr 8, 2017 at 16:48
  • @BenRacicot Yup yo're right. Back then I don't know about it. You could have improve the question though. Thanks for pointing it out. – Gujarat Santana Commented Apr 8, 2017 at 22:09
Add a ment  | 

2 Answers 2

Reset to default 10

Use the port option.

browserSync({
    port: 9999,
    server: {
      baseDir: 'app',
    }
  });

port is a direct option of BrowerSync, not a sub-option under server option.

Use ui object of browser-sync option for changing default port

var gulp = require('gulp');
var browserSync = require('browser-sync');
var livereload = require('gulp-livereload');
var reload = browserSync.reload;

// watch files for changes and reload
gulp.task('serve', function() {
  livereload.listen(1234);

  browserSync({
    server: {
      baseDir: 'app',
    },
   port: 8080
  });

  gulp.watch(['*.html', 'styles/**/*.css', 'scripts/**/*.js'], {cwd: 'app'}, reload);
});

本文标签: javascriptBrowsersync serve command with different portStack Overflow