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

SimonDegraeve/koa-browser-sync: BrowserSync middleware for Koa

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

开源软件名称:

SimonDegraeve/koa-browser-sync

开源软件地址:

https://github.com/SimonDegraeve/koa-browser-sync

开源编程语言:

JavaScript 100.0%

开源软件介绍:

koa-browser-sync

BrowserSync middleware for Koa.

Use this middleware to automatically inject the necessary browser-sync snippet into your HTML pages.

Installation

npm install koa-browser-sync --save-dev
// Use 0.x.x for Koa@1 and 1.x.x for Koa@2

Usage

There is two ways to use this module.

####1) Start browser-sync and inject the snippet with init: true (This option is set to false by default).

See the BrowserSync docs for initialization options.

var koa = require('koa');
var app = koa();

if (app.env == 'development') {
  // Use init option to start the server, default: false
  // Other options are passed directly to browser-sync
  // ex: {init:true, files: ["app/css/**/*.css"], logConnections: false}
  app.use(require('koa-browser-sync')({init: true}));
}

app.use(function (ctx, next){
  ctx.body = '<html><body>Hello World</body></html>';
});

app.listen(3000);

####2) Get the snippet from BROWSERSYNC_SNIPPET environment variable (usefull to start browser-sync from a build tool like gulp, grunt, etc)

var koa = require('koa');
var app = koa();

if (app.env == 'development') {
  // No options or {init: false}
  // The snippet must be provide by BROWSERSYNC_SNIPPET environment variable
  app.use(require('koa-browser-sync')();
}

app.use(function (ctx, next){
  ctx.body = '<html><body>Hello World</body></html>';
});

app.listen(3000);

Notes

  • All the options are passed directly to browser-sync.
  • Injection only happens on responses with a Content-Type header of text/html and containing a closing body tag </body>.

Licence

MIT License

Author

Simon Degraeve




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
mintsweet/practice: 你没有见过的终极实战发布时间:2022-07-09
下一篇:
lincenying/mmf-blog-api-koa2-v2: MMF小屋 接口koa2版发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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