Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created September 3, 2017 03:02
Show Gist options
  • Save jrobinsonc/d61ef394cae32eab359c0f524674f96f to your computer and use it in GitHub Desktop.
Save jrobinsonc/d61ef394cae32eab359c0f524674f96f to your computer and use it in GitHub Desktop.
BrowserSync using a middleware
browserSync.init({
middleware: [
// Displaying views
function (req, res, next) {
if (req.url === '/') {
req.url = '/views/index.html';
} else if (/^\/[^\/]+$/.test(req.url)) {
const file = `${__dirname}/dist/views${req.url}.html`;
if (fs.existsSync(file)) {
req.url = `/views${req.url}.html`;
}
}
return next();
}
],
server: {
baseDir: config.destDir
// serveStaticOptions: {
// extensions: ['html']
// }
},
watchEvents: ['change', 'add', 'unlink'],
ghostMode: false,
notify: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment