/
browsersync.config.js
64 lines (60 loc) · 1.57 KB
/
browsersync.config.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
/**
* Browsersync configuration
*
* Configures browsersync options for use with local dev URLs and trusted SSL certs using values from a
* `local-config.json` file which may be set up on a per-machine basis.
*
* BrowserSync Docs:
* https://browsersync.io/docs/options/
*/
const pkg = require( './package.json' );
/**
* Check if a module exists before requiring it.
*
* @param {string} name
* @return {string|void} Returns the original file name if found.
*/
function moduleExists( name ) {
try {
return require.resolve( name );
} catch ( e ) {
console.warn(
'Warning: local-config.json is missing. Did you create one?\n'
);
}
}
/**
* Populate the local config object with fallbacks.
*/
const localConfig = moduleExists( './local-config.json' )
? require( './local-config.json' )
: {
certPath: '',
certName: '',
host: 'localhost',
protocol: 'http',
};
/**
* Set up the browser sync to proxy the webpack dev server using our custom local-config.
*/
module.exports = {
debugInfo: true,
files: [
`${ pkg.config.coreThemeDir }/dist/**/*.{js,css}`,
`${ pkg.config.coreThemeDir }/**/*.{html,php}`,
`!${ pkg.config.coreThemeDir }/dist/**/*.php`,
`${ pkg.config.corePluginDir }/**/*.php`,
],
host: localConfig.host,
injectChanges: true,
logConnections: true,
notify: true,
open: 'external',
proxy: `${ localConfig.protocol }://${ localConfig.host }`,
...( localConfig.certPath.length && {
https: {
key: `${ localConfig.certPath }/${ localConfig.certName }.key`,
cert: `${ localConfig.certPath }/${ localConfig.certName }.crt`,
},
} ),
};