Skip to content

Commit

Permalink
Better BrowserSync support
Browse files Browse the repository at this point in the history
* const `watchers` is reasigned on `stop()`, changed to let
* added browsersync error handler, and bs object handler
* removed duplicated `browser` prop from browsersync defaults
* `proxy` default prop should be an object for better defaults merging
* added `server` default for more readability, note that you can define only one property `proxy` or `server`, defining both will throw an error.
  • Loading branch information
Piotr Hebda committed Nov 24, 2016
1 parent 6831f80 commit 142f09b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
/example/*
/build/*
/fractal.js
.idea/
16 changes: 11 additions & 5 deletions src/web/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,22 @@ module.exports = class Server extends mix(Emitter) {

_startSync(resolve, reject) {
const syncServer = require('browser-sync').create();
const watchers = {};
const bsConfig = _.defaultsDeep(this._config.syncOptions || {}, {
logLevel: this._config.debug ? 'debug' : 'silent',
browser: [],
logPrefix: 'Fractal',
browser: 'default',
open: false,
notify: false,
port: this._ports.sync,
proxy: this._urls.server,
server: false,
proxy: {
target: this._urls.server
},
socket: {
port: this._ports.sync,
},
});
let watchers = {};

this._app.watch();

Expand Down Expand Up @@ -156,8 +158,12 @@ module.exports = class Server extends mix(Emitter) {
watchers = {};
});

syncServer.init(bsConfig, () => {
const urls = syncServer.getOption('urls');
syncServer.init(bsConfig, (err, bs) => {
if (err) {
reject(err);
return;
}
const urls = bs.getOption('urls');
this._urls.sync = {
'local': urls.get('local'),
'external': urls.get('external'),
Expand Down

0 comments on commit 142f09b

Please sign in to comment.