diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-11-26 10:04:11 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-11-26 10:04:11 +0100 |
| commit | f99e235ae18e9c71a6381bd10d9d2a1d0bea0f19 (patch) | |
| tree | 0c05132cfdb5cda55cc6226a547c0b000cf73b05 /gui/tasks | |
| parent | 581a487b6012ea753137a1d9d3cc343d15de684d (diff) | |
| parent | 963ad808e25f7439656554878fcebc146be20f77 (diff) | |
| download | mullvadvpn-f99e235ae18e9c71a6381bd10d9d2a1d0bea0f19.tar.xz mullvadvpn-f99e235ae18e9c71a6381bd10d9d2a1d0bea0f19.zip | |
Merge branch 'upgrade-to-electron-11'
Diffstat (limited to 'gui/tasks')
| -rw-r--r-- | gui/tasks/dev-server.js | 40 | ||||
| -rw-r--r-- | gui/tasks/scripts.js | 2 | ||||
| -rw-r--r-- | gui/tasks/watch.js | 2 |
3 files changed, 43 insertions, 1 deletions
diff --git a/gui/tasks/dev-server.js b/gui/tasks/dev-server.js new file mode 100644 index 0000000000..067174ab17 --- /dev/null +++ b/gui/tasks/dev-server.js @@ -0,0 +1,40 @@ +const serverFactory = require('spa-server'); + +function startWebServer(done) { + serverFactory + .create({ + path: './build', + port: 8080, + middleware: [correctWorkingDirectory], + }) + .start(done); +} + +function correctWorkingDirectory(request, response, next) { + if (request.url === '/src/renderer/index.js') { + const write = response.write.bind(response); + response.write = (data) => { + let s = data.toString(); + + // Add code that changes to the correct working directory after `"use strict";` which is + // located on the first line of the source file. + const index = s.indexOf('\n'); + + if (index !== -1) { + const insertionIndex = index + 1; + s = + s.slice(0, insertionIndex) + + 'try{process.chdir("build/src/renderer")}catch(e){}\n' + + s.slice(insertionIndex); + } + + write(s); + }; + } + + next(); +} + +startWebServer.displayName = 'start-dev-server'; + +exports.start = startWebServer; diff --git a/gui/tasks/scripts.js b/gui/tasks/scripts.js index 5ee33a9071..37dcfa9355 100644 --- a/gui/tasks/scripts.js +++ b/gui/tasks/scripts.js @@ -8,7 +8,7 @@ function makeWatchCompiler(onFirstSuccess) { const compileScripts = function () { const watch = new TscWatchClient(); watch.on('first_success', onFirstSuccess); - watch.start('--noClear', '--sourceMap', '--incremental', '--project', '.'); + watch.start('--noClear', '--inlineSourceMap', '--incremental', '--project', '.'); return watch.tsc; }; compileScripts.displayName = 'compile-scripts-watch'; diff --git a/gui/tasks/watch.js b/gui/tasks/watch.js index 00d00e4990..fa4d301603 100644 --- a/gui/tasks/watch.js +++ b/gui/tasks/watch.js @@ -1,6 +1,7 @@ const { parallel, series, watch } = require('gulp'); const electron = require('./electron'); const hotreload = require('./hotreload'); +const devServer = require('./dev-server'); const assets = require('./assets'); const scripts = require('./scripts'); @@ -47,6 +48,7 @@ exports.start = series( // set up hotreload, run electron and begin watching filesystem for changes, after the first // successful build series( + devServer.start, hotreload.start, electron.start, parallel( |
