summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-02-15 17:51:57 +0100
committerOskar Nyberg <oskar@mullvad.net>2021-02-19 12:00:10 +0100
commit9abcb98d5cb30e8693814be648c692c5d242e20c (patch)
tree90855a8b93c8e600eb0805b9584caaef8088ec2b
parent846fb07bc4dbf9d8065daee0c78c5623f60a6751 (diff)
downloadmullvadvpn-9abcb98d5cb30e8693814be648c692c5d242e20c.tar.xz
mullvadvpn-9abcb98d5cb30e8693814be648c692c5d242e20c.zip
Improve TypeScript build process
-rw-r--r--gui/tasks/hotreload.js2
-rw-r--r--gui/tasks/scripts.js20
-rw-r--r--gui/tasks/watch.js15
3 files changed, 21 insertions, 16 deletions
diff --git a/gui/tasks/hotreload.js b/gui/tasks/hotreload.js
index 58114e1082..db0cb9bf02 100644
--- a/gui/tasks/hotreload.js
+++ b/gui/tasks/hotreload.js
@@ -31,7 +31,7 @@ function injectBrowserSync() {
function reloadBrowser(done) {
browserSync.reload();
- done();
+ done && done();
}
startBrowserSync.displayName = 'start-hotreload';
diff --git a/gui/tasks/scripts.js b/gui/tasks/scripts.js
index d32e704625..bd4626a44a 100644
--- a/gui/tasks/scripts.js
+++ b/gui/tasks/scripts.js
@@ -1,4 +1,5 @@
const { exec } = require('child_process');
+const fs = require('fs');
const { dest, series, parallel } = require('gulp');
const ts = require('gulp-typescript');
const inject = require('gulp-inject-string');
@@ -8,8 +9,10 @@ const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
-function makeWatchCompiler(onFirstSuccess) {
+function makeWatchCompiler(onFirstSuccess, onSuccess) {
let firstBuild = true;
+ let lastBundle;
+ let lastPreloadBundle;
const compileScripts = function () {
const watch = new TscWatchClient();
@@ -17,11 +20,24 @@ function makeWatchCompiler(onFirstSuccess) {
parallel(
makeBrowserifyRenderer(true),
makeBrowserifyPreload(true),
- )(() => {
+ )(async () => {
if (firstBuild) {
firstBuild = false;
onFirstSuccess();
}
+
+ let bundle = await fs.promises.readFile('./build/src/renderer/bundle.js');
+ let preloadBundle = await fs.promises.readFile('./build/src/renderer/preloadBundle.js');
+ if (
+ !lastBundle ||
+ !preloadBundle ||
+ !lastBundle.equals(bundle) ||
+ !lastPreloadBundle.equals(preloadBundle)
+ ) {
+ lastBundle = bundle;
+ lastPreloadBundle = preloadBundle;
+ onSuccess();
+ }
}),
);
watch.start('--noClear', '--sourceMap', '--inlineSources', '--incremental', '--project', '.');
diff --git a/gui/tasks/watch.js b/gui/tasks/watch.js
index dca4debe68..17b613b360 100644
--- a/gui/tasks/watch.js
+++ b/gui/tasks/watch.js
@@ -9,10 +9,6 @@ function watchMainScripts() {
return watch(['build/src/main/**/*.js'], series(electron.stop, electron.start));
}
-function watchRendererScripts() {
- return watch(['build/src/renderer/(bundle|preloadBundle).js'], series(hotreload.reload));
-}
-
function watchCss() {
return watch(['src/renderer/**/*.css'], series(assets.copyCss, hotreload.reload));
}
@@ -33,7 +29,6 @@ function watchStaticAssets() {
}
watchMainScripts.displayName = 'watch-main-scripts';
-watchRendererScripts.displayName = 'watch-renderer-scripts';
watchCss.displayName = 'watch-css';
watchConfig.displayName = 'watch-config';
watchHtml.displayName = 'watch-html';
@@ -51,14 +46,8 @@ exports.start = series(
devServer.start,
hotreload.start,
electron.start,
- parallel(
- watchMainScripts,
- watchRendererScripts,
- watchCss,
- watchConfig,
- watchHtml,
- watchStaticAssets,
- ),
+ parallel(watchMainScripts, watchCss, watchConfig, watchHtml, watchStaticAssets),
),
+ hotreload.reload,
),
);