summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <sternenseemann@systemli.org>2022-02-27 01:15:50 +0100
committersterni <sternenseemann@systemli.org>2022-02-27 10:39:22 +0100
commit14638f7395beba8dbc0b11abc6716d29825064da (patch)
tree51b2d9f2a209ff3244bb100bd0937987ddecc150
parentecf93679b92333e49306f703369677099b843439 (diff)
refactor(bahnhofshalle): use esbuild over parcel-bundler
parcel-bundler is a bit of an annoyance, as it has a million of
dependencies (in typical js fashion) and is not built by NixOS's Hydra.
An alternative to parcel-bundler is esbuild which is written in Go.

It, however, doesn't support transpiling ES6 to ES5 which we'll accept
for the lessened deployment annoyances. All modern browsers support ES6
anyways (especially the subset we are using).
-rw-r--r--.gitignore4
-rw-r--r--README.adoc15
-rw-r--r--bahnhofshalle/GNUmakefile30
-rw-r--r--bahnhofshalle/index.html2
-rw-r--r--bahnhofshalle/package.json16
-rw-r--r--default.nix24
6 files changed, 49 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
index e4d42bb..9d4a06a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,10 +8,8 @@ vgcore.*
 /warteraum/test/*.tmp
 /warteraum/test/valgrind-log.txt
 
-/bahnhofshalle/node_modules
-/bahnhofshalle/.cache
-/bahnhofshalle/yarn-error.log
 /bahnhofshalle/dist/
+/bahnhofshalle/*.js
 
 web/queue.db
 __pycache__/
diff --git a/README.adoc b/README.adoc
index 639ddd3..28bfdd8 100644
--- a/README.adoc
+++ b/README.adoc
@@ -231,14 +231,17 @@ make
 bahnhofshalle
 ~~~~~~~~~~~~~
 
-We need `parcel` and `babel`. It is probably easiest to
-either use the `bahnhofshalle` attribute of `default.nix` or `npm`
-or `yarn` to install the dependencies of `package.json` like this:
+To build `bahnhofshalle` you need GNU make and https://esbuild.github.io/[esbuild].
+One way to obtain both is to run `nix-shell -A bahnhofshalle` from the repository's
+root. To build, use the following commands:
 
 ------------------------
 cd bahnhofshalle
-yarn install
-yarn run build    # result in ./dist
+make
+firefox index.html # for local development where only js needs to be rebuilt
+
+make dist
+firefox dist/index.html # properly minified distribution
 ------------------------
 
 Note that all requests are sent using a `same-origin` policy,
@@ -354,6 +357,8 @@ Changelog
 ** Don't require `flipdot-gschichtler` to be passed as module
    argument, instead import directly from file system (unless
    a non-default derivation is configured).
+* `bahnhofshalle`
+** Switch to `esbuild`, requiring ES6 support in the browser as a result.
 
 2.0.0
 ~~~~~
diff --git a/bahnhofshalle/GNUmakefile b/bahnhofshalle/GNUmakefile
new file mode 100644
index 0000000..c1b503a
--- /dev/null
+++ b/bahnhofshalle/GNUmakefile
@@ -0,0 +1,30 @@
+DIST ?= dist
+INSTALL ?= install
+
+ESBUILDFLAGS =  --minify --bundle --platform=browser
+ESBUILDFLAGS += --target=es6,edge14,firefox51,chrome49,safari11
+
+DISTFILES =  $(DIST)/index.html
+DISTFILES += $(DIST)/favicon.ico
+DISTFILES += $(DIST)/openlab-logo.png
+DISTFILES += $(DIST)/style.css
+DISTFILES += $(DIST)/main.js
+
+all: main.js
+
+dist: $(DISTFILES)
+
+$(DIST)/%.css: %.css
+	esbuild $(ESBUILDFLAGS) $< --outfile=$@
+
+$(DIST)/%: %
+	$(INSTALL) -Dm644 $< -t $(DIST)
+
+%.js: %.es6
+	esbuild $(ESBUILDFLAGS) --loader=js --outfile=$@ < $<
+
+clean:
+	rm -f *.js
+	rm -rf $(DIST)
+
+.PHONY: clean
diff --git a/bahnhofshalle/index.html b/bahnhofshalle/index.html
index c8c3b2c..ac3a250 100644
--- a/bahnhofshalle/index.html
+++ b/bahnhofshalle/index.html
@@ -6,7 +6,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="icon" href="/favicon.ico">
     <link rel="stylesheet" href="style.css" type="text/css">
-    <script src="main.es6"></script>
+    <script src="main.js"></script>
   </head>
   <body>
     <header>
diff --git a/bahnhofshalle/package.json b/bahnhofshalle/package.json
deleted file mode 100644
index 3240921..0000000
--- a/bahnhofshalle/package.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "name": "bahnhofshalle",
-  "version": "2.0.0",
-  "devDependencies": {
-    "@babel/core": "^7.11.6",
-    "parcel-bundler": "^1.12.4"
-  },
-  "babel": {
-    "presets": [
-      "@babel/preset-env"
-    ]
-  },
-  "scripts": {
-    "build": "parcel build index.html --out-dir=\"dist\" --no-source-maps"
-  }
-}
diff --git a/default.nix b/default.nix
index 4021a7b..33d10a4 100644
--- a/default.nix
+++ b/default.nix
@@ -35,25 +35,15 @@ rec {
 
     src = rootSrc + "/bahnhofshalle";
 
-    buildInputs = [ pkgs.nodePackages.parcel-bundler ];
+    nativeBuildInputs = [
+      pkgs.buildPackages.esbuild
+    ];
 
-    buildPhase = ''
-      # inform parcel builder about our job count preferences
-      export PARCEL_WORKERS=$NIX_BUILD_CORES
-      # parcel won't find its dependencies unless they are in the current directory
-      ln -s "${pkgs.nodePackages.parcel-bundler}/lib/node_modules/parcel-bundler/node_modules" ./node_modules
+    makeFlags = [
+      "DIST=$(out)"
+    ];
 
-      parcel build index.html --out-dir="dist" --no-source-maps
-
-      # fail if parcel doesn't produce an output
-      if [[ "$(find dist | wc -l)" -le 1 ]]; then
-        exit 1
-      fi
-    '';
-
-    installPhase = ''
-      cp -r dist $out
-    '';
+    installTargets = [ "dist" ];
   };
 
   anzeigetafel =