-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (51 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
// Module:
var browserSync = require('browser-sync');
var bus = null;
module.exports = {
refresh: function () {
return browserSync.reload();
},
refreshStream: function () {
return browserSync.stream();
},
register: register,
serverTask: serverTask
}
function serverTask (options) {
options = config(options);
// Bus:
if (bus) {
bus.on('notify-error', function (message, title) {
var notify = '<b>' + title + ':</b> ' + message;
browserSync.notify(notify, options.notifyDuration)
});
}
// Task:
return function () {
var config = {
port: options.port,
middleware: options.middleware,
open: false
};
if (options.proxy) {
config.proxy = options.proxy;
} else {
config.server = options.root;
}
browserSync.init(config);
}
}
function config (options) {
// Defaults:
options = options || {};
options.port = options.port || 8080;
options.proxy = options.proxy || null;
options.root = options.root || './build';
options.notifyDuration = options.notifyDuration || 10000;
options.middleware = options.middleware || [];
return options;
}
function register (b) {
bus = b;
}