Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This file configures a web server for testing the production build
// on your local machine.
import path from 'path';
import browserSync from 'browser-sync';
import historyApiFallback from 'connect-history-api-fallback';
import {chalkProcessing} from './chalkConfig';
import { projectPath } from './settings';
/* eslint-disable no-console */
console.log(chalkProcessing('running a dist server on http://localhost:4000 ...'));
// Run Browsersync
const result = browserSync({
port: 4000,
ui: {
port: 4001
},
open: false,
server: {
baseDir: path.resolve(projectPath, 'dist')
},
files: [
'src/*.html'
],
ghostMode: false,
middleware: [
function (req, res, next) {
const contentPath = path.resolve(projectPath, 'dist', 'prerender.html');
gulp.task('browsersync', cb => {
browserSync({
logPrefix: 'VRT',
notify: false,
https: false,
proxy: 'localhost:3000'
}, cb);
process.on('exit', () => browserSync.exit());
});
return new Promise((resolve, reject) => {
browserSync(taskConf, (err, bs) => {
if (err) {
return reject();
}
return resolve(bs);
});
});
}
function setupBrowserSync() {
return browsersync(config)
}
done => {
browserSync({
online: false,
open: false,
port: 9000,
server: {
baseDir: ['.'],
middleware: function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
}
}
}, done);
}
);
break;
}
injectBrowserSync.push('');
injectBrowserSync.push(bsHtmlSnippet);
injectBrowserSync = injectBrowserSync.join('\n');
config.rewriteRules = [
{
match: //g,
fn: function (match) {
return injectBrowserSync;
}
}
];
}
browserSync(config);
}
gulp.task('server', () => sync(options))
Gulp.task('browserSync', () => {
return BrowserSync(config.tasks.browserSync);
});