Building static binaries with TypeScript
The ability to shamelessly ask stupid questions has led me to numerous interesting projects and in some cases truly novel solutions. The subject of this blog post fits into the first part of that equation at least. I find the single static binaries produced by Rust and Golang to be quite compelling for system utilities, at the same time however I am fond of writing TypeScript. Why can’t I mix chocolate with my peanut butter?
You kinda can! And it kinda works!
I first started tinkering with a tool which I discovered while goofy-hacking months ago: nexe. Nexe helps turn Node applications into single static binaries with an embedded Node runtime. I had issues with newer style imports, which weren’t working properly with the system Nexe uses to build its bundles. I went looking around for other options. Eventually I stumbled into Pkg which worked quite well!
pkg with TypeScript works with the simple addition of a
invocation before calling
pkg. Passing in the
build/ directory containing the
static binary is generated. I have a suspicion that
pkg won’t work effectively
with Node packages that include native code, but haven’t yet walked into that
Are static binaries which embed Node possible, definitely! Are they a good idea … maybe! I’m looking for more interesting projects to explore the concept in the future, but for now it’s filed under “interesting novelties.”