@achingbrain/gulp-connect 中文文档教程

发布于 6年前 浏览 16 项目主页 更新于 3年前

gulp-connect Build StatusJoin the chat at https://gitter.im/AveVlad/gulp-connect

运行网络服务器的 Gulp 插件(使用 LiveReload)gulp

Sponsors

-connect 由 JetBrains 赞助!

Install

npm install --save-dev gulp-connect

Usage

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

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

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(gulp.dest('./app'))
    .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({
    name: 'Dev App',
    root: ['app', 'tmp'],
    port: 8000,
    livereload: true
  });
});

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

gulp.task('html', function () {
  gulp.src('./app/*.html')
    .pipe(gulp.dest('./app'))
    .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']);

http2 support

如果 http2 包已安装并且您使用 https 连接 gulp connect 然后将优先使用 http 2 而不是 http 1。

API

options.root

类型:<代码>数组或字符串 默认值:Directory with gulpfile

根路径

options.port

类型:Number 默认值:8080

连接网络服务器端口

options.host

类型:String 默认值:localhost

options.name

类型:String 默认值:Server

服务器启动/停止时输出的名称。

options.https

类型:<代码>对象 默认值:false

可以是 https://nodejs.org/api/https.html#httpshttpscreateserveroptionsrequestlistener 中记录的任何

选项https 只是设置为 true(布尔值),然后在内部将使用一些默认值。

options.livereload

类型:对象或布尔值 默认值:false

options.livereload.port

类型:Number 默认值:35729

覆盖 index.html 中注入的脚本 livereload 的主机名

options.livereload.hostname

类型:String 默认值:'undefined'

options.fallback

类型:String 默认值:undefined

后备文件(例如 index.html

options.middleware

类型:Function 默认值:[]

options.debug

类型:Boolean 默认值:false

options.index

类型:新索引传递的布尔值或字符串或按首选顺序排列的新索引数组 默认值:true

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

Contributing

要参与此项目,您必须安装 CoffeeScript:npm install -g coffee-script

然后,要构建 index.js 文件,请运行 coffee -o 。 -bc 源/。 运行 npm test 以运行测试。

Contributors

gulp-connect Build StatusJoin the chat at https://gitter.im/AveVlad/gulp-connect

Gulp plugin to run a webserver (with LiveReload)

Sponsors

gulp-connect is sponsored by JetBrains!

Install

npm install --save-dev gulp-connect

Usage

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

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

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(gulp.dest('./app'))
    .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({
    name: 'Dev App',
    root: ['app', 'tmp'],
    port: 8000,
    livereload: true
  });
});

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

gulp.task('html', function () {
  gulp.src('./app/*.html')
    .pipe(gulp.dest('./app'))
    .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']);

http2 support

If the http2 package is installed and you use an https connection to gulp connect then http 2 will be used in preference to http 1.

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.name

Type: String Default: Server

The name that will be output when the server starts/stops.

options.https

Type: Object Default: false

Can be any options documented at https://nodejs.org/api/https.html#httpshttpscreateserveroptionsrequestlistener

When https is just set to true (boolean), then internally some defaults will be used.

options.livereload

Type: Object or Boolean Default: false

options.livereload.port

Type: Number Default: 35729

Overrides the hostname of the script livereload injects in index.html

options.livereload.hostname

Type: String Default: 'undefined'

options.fallback

Type: String Default: undefined

Fallback file (e.g. index.html)

options.middleware

Type: Function Default: []

options.debug

Type: Boolean Default: false

options.index

Type: Boolean or String of a new index pass or Array of new indexes in preferred order Default: true

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

Contributing

To contribute to this project, you must have CoffeeScript installed: npm install -g coffee-script.

Then, to build the index.js file, run coffee -o . -bc src/. Run npm test to run the tests.

Contributors

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文