3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gulp-webserver

Last updated at Posted at 2016-07-12

##install

$ npm install -D gulp-webserver

##Usage Basic

var gulp = require('gulp');
var webserver = require('gulp-webserver');
 
gulp.task('webserver', function() {
  gulp.src('dist') //任意のフォルダー htdocsとか
    .pipe(webserver({
      host: 'localhost',
      port: 9001, //任意のport番号
      livereload: true, //ライブリロード
      directoryListing: false //directory表示
      open: true
    }));
});

###Option Exmple1

  • 任意のファイルを開きたい場合
var gulp = require('gulp');
var webserver = require('gulp-webserver');

gulp.task('webserver', function() {
  gulp.src('dist')
    .pipe(webserver({
      host: 'localhost',
      port: 9001;
      livereload: true,
      open : 'http://localhost:9001/index.html' //任意のファイルを開きたいときはパスを指定
    }));
});

###Option Exmple2(SSI IP)

  • SSIを利用する場合(プラグイン追加)
  • IPアドレスでアクセスする場合(プラグイン追加)
npm install -D connect-ssi
npm install -D my-ip
var gulp = require('gulp');
var webserver = require('gulp-webserver');
var connectSSI = require('connect-ssi');
var ip = require('my-ip');

gulp.task('webserver', function() {
  gulp.src('dist')
    .pipe(webserver({
      host: '0.0.0.0', //IPアドアレスでアクセスする場合は「0.0.0.0」をセットしてMY-IPでアクセス
      port: 9001;
      livereload: true,
      middleware: [
		connectSSI({// connectSSI
		 ext: '.html', // file extension. Only urls ending in this will be evaluated.
		 baseDir: 'htdocs'//  BasePath
		})
      ],
      open : 'http://'+ ip() +':9001/index.html'
    }));
});

###DefultTask

gulp.task('default', ['webserver']);
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?