gulp-connect-pm2
Gulp plugin to run a webserver (with LiveReload and pm2) forked from https://github.com/AveVlad/gulp-connect
Last updated 5 years ago by ianzhao2010 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gulp-connect-pm2 
SYNC missed versions from official npm registry.

gulp-connect-pm2

Gulp plugin to run a webserver (with LiveReload and pm2) , forked from AveVlad/gulp-connect

Install

npm i gulp-connect-pm2

required :

npm -g install pm2

Usage


var connect, exec, gulp;

gulp    = require('gulp');
connect = require('gulp-connect-pm2');
exec    = require('child_process').exec;

gulp.task('connect', function() {
  connect.server();
});

gulp.task('stop', function(cb) {
  exec('sudo pm2 stop all', function(err, stdout, stderr) {});
  console.log(stdout);
  console.log(stderr);
  cb(err);
});

gulp.task('default', ['connect']);

LiveReload

var gulp = require('gulp'),
  connect = require('gulp-connect');

gulp.task('connect', function() {
  connect.server({
    root: 'app',
    livereload: true
  });
});

gulp.task('html', function () {
  gulp.src('./app/*.html')
    .pipe(connect.reload());
});

gulp.task('watch', function () {
  gulp.watch(['./app/*.html'], ['html']);
});

gulp.task('default', ['connect', 'watch']);

Start and stop server

gulp.task('jenkins-tests', function() {
  connect.server({
    port: 8888
  });
  // run some headless tests with phantomjs
  // when process exits:
  connect.serverClose();
});

Multiple server

var gulp = require('gulp'),
  stylus = require('gulp-stylus'),
  connect = require('gulp-connect');

gulp.task('connectDev', function () {
  connect.server({
    root: ['app', 'tmp'],
    port: 8000,
    livereload: true
  });
});

gulp.task('connectDist', function () {
  connect.server({
    root: 'dist',
    port: 8001,
    livereload: true
  });
});

gulp.task('html', function () {
  gulp.src('./app/*.html')
    .pipe(connect.reload());
});

gulp.task('stylus', function () {
  gulp.src('./app/stylus/*.styl')
    .pipe(stylus())
    .pipe(gulp.dest('./app/css'))
    .pipe(connect.reload());
});

gulp.task('watch', function () {
  gulp.watch(['./app/*.html'], ['html']);
  gulp.watch(['./app/stylus/*.styl'], ['stylus']);
});

gulp.task('default', ['connectDist', 'connectDev', 'watch']);

API

options.root

Type: Array or String Default: Directory with gulpfile

The root path

options.port

Type: Number Default: 8080

The connect webserver port

options.host

Type: String Default: localhost

options.https

Type: Boolean Default: false

options.livereload

Type: Object or Boolean Default: false

options.livereload.port

Type: Number Default: 35729

options.fallback

Type: String Default: undefined

Fallback file (e.g. index.html)

options.middleware

Type: Function Default: []

gulp.task('connect', function() {
  connect.server({
    root: "app",
    middleware: function(connect, opt) {
      return [
        // ...
      ]
    }
  });
});

Contributors

AveVlad and schickling

Current Tags

  • 0.0.2                                ...           latest (5 years ago)

2 Versions

  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (8)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |