diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-02-06 10:38:18 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-02-06 10:38:18 +0000 |
| commit | cc4362f9f0edb702ed85820addaf13d7ee758423 (patch) | |
| tree | 6938111907ec73cdc41130876fb1f6b40cf619a9 /scripts | |
| download | mullvadvpn-cc4362f9f0edb702ed85820addaf13d7ee758423.tar.xz mullvadvpn-cc4362f9f0edb702ed85820addaf13d7ee758423.zip | |
Initial commit
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/serve.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/serve.js b/scripts/serve.js new file mode 100644 index 0000000000..6b5001a237 --- /dev/null +++ b/scripts/serve.js @@ -0,0 +1,52 @@ +import { spawn } from 'child_process'; +import electron from 'electron'; +import browserSync from 'browser-sync'; +import browserSyncConnectUtils from 'browser-sync/lib/connect-utils'; + +const bsync = browserSync.create(); + +const getRootUrl = (options) => { + const port = options.get('port'); + return `http://localhost:${port}`; +}; + +const getClientUrl = (options) => { + const pathname = browserSyncConnectUtils.clientScript(options); + return getRootUrl(options) + pathname; +}; + +bsync.init({ + ui: false, + // Port 35829 = LiveReload's default port 35729 + 100. + // If the port is occupied, Browsersync uses next free port automatically. + port: 35829, + ghostMode: false, + open: false, + notify: false, + logSnippet: false, + socket: { + // Use the actual port here. + domain: getRootUrl + } +}, (err, bs) => { + if (err) return console.error(err); + + const child = spawn(electron, ['.'], { + env: { + ...{ + NODE_ENV: 'development', + BROWSER_SYNC_CLIENT_URL: getClientUrl(bs.options) + }, + ...process.env + }, + stdio: 'inherit' + }); + + child.on('close', () => { + process.exit(); + }); + + bsync + .watch('build/**/*') + .on('change', bsync.reload); +}); |
