-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbrowser-sync.js
74 lines (72 loc) · 2.1 KB
/
browser-sync.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
62
63
64
65
66
67
68
69
70
71
72
73
74
const browserSync = require('browser-sync').create('server');
const path = require('path');
const _ = require('lodash');
module.exports = (gulp, config, tasks) => {
const watchFiles = [];
if (config.css.enabled) {
watchFiles.push(path.join(config.css.dest, '*.css'));
}
if (config.browserSync.watchFiles) {
config.browserSync.watchFiles.forEach((file) => {
watchFiles.push(file);
});
}
const options = {
browser: config.browserSync.browser,
files: watchFiles,
port: config.browserSync.port,
tunnel: config.browserSync.tunnel,
open: config.browserSync.openBrowserAtStart,
reloadOnRestart: true,
reloadDelay: config.browserSync.reloadDelay,
reloadDebounce: config.browserSync.reloadDebounce,
// https://www.browsersync.io/docs/options#option-middleware
middleware: config.browserSync.middleware || [],
// https://www.browsersync.io/docs/options#option-rewriteRules
rewriteRules: config.browserSync.rewriteRules || [],
// placing at `</body>` instead of `<body>`
snippetOptions: {
rule: {
match: /<\/body>/i,
fn: (snippet, match) => snippet + match,
},
},
notify: {
styles: [
'display: none',
'padding: 15px',
'font-family: sans-serif',
'position: fixed',
'font-size: 0.9em',
'z-index: 9999',
'bottom: 0px',
'right: 0px',
'border-bottom-left-radius: 5px',
'background-color: #1B2032',
'margin: 0',
'color: white',
'text-align: center',
],
},
};
if (config.browserSync.domain) {
_.merge(options, {
proxy: config.browserSync.domain,
startPath: config.browserSync.startPath,
serveStatic: config.browserSync.serveStatic || [],
});
} else {
_.merge(options, {
server: {
baseDir: config.browserSync.baseDir,
},
startPath: config.browserSync.startPath,
});
}
function serve() {
return browserSync.init(options);
}
serve.description = 'Create a local server using BrowserSync';
gulp.task('serve', serve);
tasks.default.push('serve');
};