sick-sad-world
2/20/2017 - 7:49 PM

Default task to launch browserSync server

Default task to launch browserSync server

const browserSync = require('browser-sync').create();
const path = require('path');

// Middleware to help seve index.html file on all non-file paths
// To enable it - put it in [middleware] property of Browsersync
// server options (near [base])
const SPAMiddleware = (req, res, next) => {
  if (req.url.indexOf('.') < 0) req.url = '/index.html';
  return next();
}

// @name - project nam for logging
// @BASE - Base dir to serve
// @watch - Paths to watch for changes app.js, app.css, index.html for example
module.exports = (name, BASE, watch) => browserSync.init({
  port: 3000,
  open: true,
  online: true,
  notify: false,
  logLevel: 'info',
  logPrefix: name,
  logConnections: true,
  logFileChanges: true,
  server: {
    baseDir: BASE
  }, 
  files: watch.map((p) => path.join(BASE, p)),
  watchOptions: {
    ignored: /node_modules/
  }
});