Created
September 3, 2017 03:02
-
-
Save jrobinsonc/d61ef394cae32eab359c0f524674f96f to your computer and use it in GitHub Desktop.
BrowserSync using a middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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