• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

gimm/gulp-express: gulp plugin for express

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

gimm/gulp-express

开源软件地址(OpenSource Url):

https://github.com/gimm/gulp-express

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

please use gulp-live-server instead, it's a new version of gulp-express with a better name and new features.

Build Status Livereload downloads Tag MIT Licensed

A gulp plugin which serve the app with livereload, internally, it does the following:

Install

NPM

Update notice

  • v0.3.0

    change signature of server.run. the third param livereload is used to config tiny-lr server.

  • v0.2.0

    get console.log back.

  • v0.1.12

    options.lr is used for creating tiny-lr server. options here is the second parameter for server.run.

  • v0.1.7

    change signature for server.run, split options into args and options.

  • v0.1.5

    pipe support added for server.notify

API

server.run([args][,options][,livereload])

Run/re-run the script file, which will create a http(s) server.

Start a livereload(tiny-lr) server if it's not started yet.

Use the same arguments with ChildProcess.spawn with 'node' as command.

  • args - Array - Array List of string arguments. The default value is ['app.js'].
  • options - Object - The third parameter for ChildProcess.spawn, the default value is:
options = {
    cwd: undefined
}
options.env = process.env;
options.env.NODE_ENV = 'development';
  • livereload - Boolean|Number|Object - The option for tiny-lr server. The default value is 35729.
    • false - will disable tiny-lr livereload server.
    • number - treated as port number of livereload server.
    • object - used to create tiny-lr server new tinylr.Server(livereload);.
  • Returns a ChildProcess instance of spawned server.

server.stop()

Stop the instantiated spawned server programmatically, and the tiny-lr server.

server.notify([event])

Send a notification to the tiny-lr server in order to trigger a reload on page. pipe support is added after v0.1.5, so you can also do this:

gulp.src('css/*.css')
// …
.pipe(gulp.dest('public/css/'))
.pipe(server.notify())
  • event (required when server.notify is invoked without pipe) - Object - Event object that is normally passed to gulp.watch callback. Should contain path property with changed file path.

Usage

// gulpfile.js
var gulp = require('gulp');
var server = require('gulp-express');

gulp.task('server', function () {
    // Start the server at the beginning of the task
    server.run(['app.js']);

    // Restart the server when file changes
    gulp.watch(['app/**/*.html'], server.notify);
    gulp.watch(['app/styles/**/*.scss'], ['styles:scss']);
    //gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]);
    //Event object won't pass down to gulp.watch's callback if there's more than one of them.
    //So the correct way to use server.notify is as following:
    gulp.watch(['{.tmp,app}/styles/**/*.css'], function(event){
        gulp.run('styles:css');
        server.notify(event);
        //pipe support is added for server.notify since v0.1.5,
        //see https://github.com/gimm/gulp-express#servernotifyevent
    });

    gulp.watch(['app/scripts/**/*.js'], ['jshint']);
    gulp.watch(['app/images/**/*'], server.notify);
    gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
});
// app.js
var express = require('express');
var app = module.exports.app = exports.app = express();

//you won't need 'connect-livereload' if you have livereload plugin for your browser
app.use(require('connect-livereload')());



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
dowjones/gulp-bundle-assets: Create static asset (js, css) bundles from a config ...发布时间:2022-06-21
下一篇:
Nunjucks发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap