çæ§ã¯ããã¾ãã¦ãã¡ããã¢ã¨ã³ã¸ãã¢ã®ä¸æã§ãã
好ããªãã©ã¦ã¶ã¯ Vivaldi ã§ãã
æ¬è¨äºã§ã¯Webéçºå¹çåã®çºã®ã²ã¨ã¤ã®æ段ã¨ãã¦ãBrowsersyncã®å©ç¨æ¹æ³ã¨å¹¾ã¤ãã®æ©è½ããç´¹ä»ãã¾ãã
Browsersyncã¨ã¯
Browsersyncã¯ãã¡ã¤ã«å¤æ´ãç£è¦ããèªåã§ãã©ã¦ã¶ãªãã¼ããè¡ã£ã¦ããããã¼ã«ã§ãã
Browsersync - Time-saving synchronised browser testing
å種ã®ãã¼ã«ã¨ãã¦LiveReloadãæåã§ããã
- ãã©ã¦ã¶å´ã§Extentionãæ¡å¼µãä¸è¦
- è¤æ°ãã©ã¦ã¶ã§æä½ã®åæãã§ãã
- ãã®ä»ã®æ©è½ãè±å¯
ãªã©ã®ã¡ãªãããããæè¿ã¯Browsersyncã®æ¹ã人æ°ã®ããã§ãã
ãã£ããBrowsersyncã試ãã¦ã¿ãã
ã¾ãã¯Browsersyncãã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ãããã
nodeã®ããã±ã¼ã¸ããã¼ã¸ã£ã§ããnpmã³ãã³ãããã¤ã³ã¹ãã¼ã«å¯è½ã§ãã
ã¤ã³ã¹ãã¼ã«ã³ãã³ã
$ npm install browser-sync --save-dev # localç°å¢ã«ã¤ã³ã¹ãã¼ã« $ npm install browser-sync -g # globalç°å¢ã«ã¤ã³ã¹ãã¼ã«
ããã§ã¤ã³ã¹ãã¼ã«å®äºã§ãã
ã§ã¯Browsersyncãå®è¡ãã¦ã¿ã¾ãããã
ãªãããµã³ãã«ã¨ãã¦ã¾ãã¯ä»¥ä¸ã®ãããªã·ã³ãã«ãªãµã¤ãæ§æã§è§£èª¬ãã¾ãã
. âââ css â  âââ main.css âââ index.html
index.htmlã¯main.cssãåç §ãã¦ãããã®ã¨ãã¾ãã
ã§ã¯ã³ãã³ãå®è¡ãã¦ã¿ã¾ãã
$ browser-sync start --server --files "**/*" [BS] Access URLs: ------------------------------------- Local: http://localhost:3000 External: http://192.168.0.57:3000 ------------------------------------- UI: http://localhost:3001 UI External: http://192.168.0.57:3001 ------------------------------------- [BS] Serving files from: ./ [BS] Watching files...
ã³ãã³ãå®è¡å¾ãä¸è¨ã®ãããªãã°ã¡ãã»ã¼ã¸ãconsoleã«æµãã¤ã¤ãããã©ã«ããã©ã¦ã¶ã®æ°ããã¿ãã« http://localhost:3000 ã«ããããµã¤ãã表示ãããããºã§ãã
â» ããã§ã¯ãµã³ãã«ã¨ã㦠Bootstrapã®example ãå©ç¨ãã¦ãã¾ãã
ãã®ç¶æ ã®ã¾ã¾ã試ãã«cssãç·¨éãã¦ã¿ã¾ãããã
body { background-color: #ccc; }
ããã¨èªåã§æ´æ°å 容ãåæ ããã¾ãããããã§ããã
--files ãªãã·ã§ã³ã«globãã¿ã¼ã³ã§æå®ãããã¡ã¤ã«ç¾¤ãwatchãããã¡ã¤ã«ã«å¤æ´ãããã°èªåã§ãªãã¼ããã¦ããã¾ãã
ããã¯LiveReloadã¨ä¸ç·ã§ããã
Browsersyncã§ã§ããã³ã
ä»ã«ãæ§ã ãªæ©è½ãããã®ã§å¹¾ã¤ããç´¹ä»ãã¾ãã
ãããã·å®è¡
--server ãªãã·ã§ã³ã®ä»£ããã« --proxy ãªãã·ã§ã³ãå©ç¨ããã¨ãããã·ã¨ãã¦å®è¡ãããã¨ãå¯è½ã§ãã
$ browser-sync start --proxy "sugoi-service.jp" --files "**/*"
ãã¼ã«ã«å ±æ
åè¿°ã®éãBrowsersyncå®è¡æã«ã
$ browser-sync start --server --files "**/*" [BS] Access URLs: ------------------------------------- Local: http://localhost:3000 External: http://192.168.0.57:3000 ------------------------------------- UI: http://localhost:3001 UI External: http://192.168.0.57:3001 ------------------------------------- [BS] Serving files from: ./ [BS] Watching files...
ã®ãããªãã°ã¡ãã»ã¼ã¸ãæµãã¾ãã
ãã¼ã«ã«ãããã¯ã¼ã¯ä¸ã§ã¯ãã® http://192.168.0.57:3000 ã¸ã¢ã¯ã»ã¹ãã¦ãé²è¦§å¯è½ã§ãã
ãã£ããã£ç»åãSlackã§ããã¨ãããã¨ãã¡ãã£ã¡ãã£ã¨éçºç»é¢å
±æãã§ãã¾ããã
bs-configãã¡ã¤ã«(è¨å®ãã¡ã¤ã«)ã«ããå®è¡
æ¯åç´°ãããªãã·ã§ã³ãä»ä¸ãã¦å®è¡ããã®ã¯é¢åã§ãã
bs-config.jsã¨ããè¨å®ãã¡ã¤ã«ãç¨æãã
$ browser-sync start --config bs-config.js
ã®ããã«--configãªãã·ã§ã³ã§bs-config.jsãã¡ã¤ã«ãæå®å®è¡ããã°æ¯ååãè¨å®ã§èµ·åå¯è½ã§ãã
ãªããbs-config.jsãã¡ã¤ã«ã¯ã
$ browser-sync init
ã§çæå¯è½ãªã®ã§ããã¡ãã§ããã©ã«ãè¨å®ã®bs-config.jsãçæããã好ã¿ã§è¨å®ããã¨ä¾¿å©ã§ãã
ãªãã¼ãã®ã¦ã§ã¤ããwatch対象ã®ãã¡ã¤ã«ç¾¤æå®/é¤å¤ããã°åºåè¨å®ãªã©ã30å以ä¸ã®ãªãã·ã§ã³ãããã¾ãã
å
¨ãªãã·ã§ã³ã¯ Browsersync options ãåèã«ãã¦ãã ããã
Browesersync管çç»é¢
Browsersyncã«ã¯ç®¡çç»é¢ãã¤ãã¦ãã¾ãã
ããã©ã«ãã§ã¯ http://localhost:3001 ã管çç»é¢ã§ãããããBrowsersyncãèµ·åããã¾ã¾å¹¾ã¤ãã®ãªãã·ã§ã³ãåãæ¿ãå¯è½ã§ãã
ãã©ã¦ã¶åæ
å人çã«Browesersyncã®ç®çã ã¨æã£ã¦ããæ©è½ã§ãã
è¤æ°ãã©ã¦ã¶ã§ã¯ãªãã¯, ã¹ã¯ãã¼ã«, ãã©ã¼ã æä½ãåæãããã¨ãã§ãã¾ãã
ãªã«ãå¬ããã®ãã¨ããã¨ã
ã®ããã«PC/ã¹ããããããã®ã¦ã£ã³ãã¦å¹
ã«ããç¶æ
ã§éçºããã¨ãã¬ã¹ãã³ã·ããã¶ã¤ã³ç°å¢ã§ãã¹ã ã¼ãºã«ç¢ºèªå¯è½ã§ãã
ã¾ããå種ã¤ãã³ããåæãããã®ã§ãã¼ã«ã«ã§ã®ã¯ãã¹ãã©ã¦ã¶ç¢ºèªã容æã«è¡ããã¨ãã§ãã¾ããã
modernIEãiOSã·ãã¥ã¬ã¼ã¿ãã確èªããã®ã«ãæç¨ã§ãã
ãªã¢ã¼ããããã°æ©è½
åè¦ç´ ã®ã¢ã¦ãã©ã¤ã³è¡¨ç¤ºããã°ãªãã表示ãè¡ããã¨ãå¯è½ã§ãã
ã¡ãªã¿ã«CSSã¢ã¦ãã©ã¤ã³è¡¨ç¤ºæ©è½ãã®ä»ã®ãã£ã«ã¿ãªã³ã°æ©è½ã¯ Vivaldi ã«ã¯ãã©ã¦ã¶ã«æåããçµã¿è¾¼ã¾ãã¦ãã¾ããä»ããã¤ã³ã¹ãã¼ã«ãã¾ãããã
ãããã¯ã¼ã¯å¶é
Chrome ã«ãåæ§ã®æ©è½ãããã¾ãããç¹å®ãã©ã¦ã¶ã§ã®ãããã¯ã¼ã¯å¶éä¸ã§ã®ãã¹ãã試ãããå ´åã«ã¯æç¨ããããã¾ããã
Gulpã«Browesersyncãçµã¿è¾¼ã
LESS/SassãTypeScript/CoffeeScriptã®ã³ã³ãã¤ã«ãminifyã®çºã«æ¢ã«Gulp/Gruntãå©ç¨ãã¦ããã±ã¼ã¹ããããã¨æãã¾ãã
ãã®å ´åã以ä¸ã®ãããªgulpfile.jsãè¨è¿°ããã° gulp
ã³ãã³ãã§å®è¡å¯è½ã§ãã
var gulp = require('gulp'); var browserSync = require('browser-sync').create(); // éçãã¡ã¤ã«ã®ã¿å ´å gulp.task('browser-sync', function() { browserSync.init({ server: { baseDir: "./" } }); }); // ãããã·å®è¡ã®å ´å gulp.task('browser-sync', function() { browserSync.init({ proxy: "sugoi-service.jp" }); }); gulp.task('default', ['browser-sync']);
åæ§ã«Gruntã«ãçµã¿è¾¼ã¿å¯è½ã§ããBrowsersync + Grunt.js
ã¾ããGulpãGruntã§å©ç¨ã§ããAPIã®ããã¥ã¡ã³ããå
¬éããã¦ãã¾ããBrowsersync API
gulpfile.jsã«çµã¿è¾¼ãã§ãã¾ãã°ãè¤æ°ãµã¤ããåæã«ç«ã¡ããããã¨ãã§ãã¾ãã®ã§ãgulpfile.jsã«ãã¹ã¦å¯ãã¦ãã¾ã£ãæ¹ã便å©ã§ãããã
ã¾ã¨ã
Browsersyncãå©ç¨ããã¨ããªãã¼ãã®æéãçãã¤ã¤ãã©ã¦ã¶ç¢ºèªã容æã«ãªãã¾ãã
æ¢åã®Gulp/Gruntç°å¢ã¸ã®çµã¿è¾¼ã¿ãã«ã³ã¿ã³ã§ãã®ã§ãã²è©¦ãã¦ã¿ã¦ãã ããã