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

BrowsersyncのExternal URLをQRコードで表示する

Posted at

開発中、スマホやタブレットなどでBrowsersyncのExternal URLにアクセスしたい時があると思うんですが、
ターミナルにQRコードが直接表示されたら便利だなと思ってやってみました。

方法

gtanner/qrcode-terminalを使いました。

// インストール
$ npm i -D qrcode-terminal

gulpfile.babel.js

gulpfile.babel.js
'use strict';
import gulp from 'gulp';
import browserSync from 'browser-sync';
import qr from 'qrcode-terminal';

const opt = {
  server: 'app',
  open: true,
  notify: true,
  ghostMode: false
}

gulp.task('browser-sync', ()=>{
  const instance = browserSync.init(opt, ()=>{
    // External URL
    let url = instance.getOption('urls').get('external');
    // Generate qrcode
    qr.generate(url);
  });
});

結果

できました。ちょっと便利。
bs.png

参考

5
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
5
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?