LoginSignup
4
4

More than 5 years have passed since last update.

手っ取り早くlivereload環境構築

Posted at

node & npm

[vagrant@localhost]$ node -v
v4.2.3
[vagrant@localhost]$ npm -v
3.8.2

必要パッケージの用意

$ npm init -y
$ npm install -g gulp
$ npm install --save-dev browser-sync gulp

.gitignore

#追記
node_modules/

gulpfile.js

var gulp          = require("gulp");
var browserSync   = require('browser-sync').create();
var reload        = browserSync.reload;

gulp.task('default', ['server'], function() {
  gulp.watch('Watch Dir', ['reload']);
});

gulp.task('server', function() {
  browserSync.init({
      debugInfo: true,
      open: false,
      host: "Your Host"
  });
});

gulp.task('reload', function() {
  return browserSync.reload();
});

起動

$ gulp
# こんなメッセージがでるはず
...
...
[BS] Copy the following snippet into your website, just before the closing </body> tag
<script id="__bs_script__">//<![CDATA[
    document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.2.11.2.js'><\/script>".replace("HOST", location.hostname));
//]]></script>
...
...
# bodyタグ直前に上記スクリプトを追加する

watch対象を変更した時

[13:31:02] Starting 'reload'...
[BS] Reloading Browsers...
[13:31:02] Finished 'reload' after 2.15 ms
#変更が反映されてればok
4
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
4
4