Skip to content

Instantly share code, notes, and snippets.

@pjchender
Created July 31, 2017 02:31
Show Gist options
  • Save pjchender/9b3e913e77da81681182d956be5cd369 to your computer and use it in GitHub Desktop.
Save pjchender/9b3e913e77da81681182d956be5cd369 to your computer and use it in GitHub Desktop.
Gulp BrowserSync
tags: gulp, browsersync, browser reload, autoreload

This is a simple web server for auto browsersync.

const gulp = require('gulp')
const browserSync = require('browser-sync').create()
// Static Server + watching scss/html files
gulp.task('serve', function () {
browserSync.init({
proxy: 'http://localhost:3000/'
})
gulp.watch('./../shopping-mall/app/**/*.{css,js,erb}', ['browser-reload'])
})
gulp.task('browser-reload', function (done) {
browserSync.reload()
done()
})
gulp.task('default', ['serve'])
{
"name": "pjchender-gulp-template",
"version": "0.0.6",
"description": "",
"main": "index.js",
"scripts": {
"start": "gulp",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.18.8",
"gulp": "^3.9.1"
}
}
@pjchender
Copy link
Author

Watch everything below folder

The pattern for all files under all directories is usually ./src/less/**/*.* or ./src/less/**/*, either should work.

Generally speaking, it's better to match specific files extensions — even if they should all be the same — to prevent grabbing system files or other junk. In that case, you can do ./src/less/**/*.less for just .less files, or something like .src/less/**/*.{less,css} for both .less and .css files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment