How to avoid large distributions with pkg?

We build applications with Node and pkg, then build a debian file around the generated binary, and distribute that debian file on a repo managed with aptly, where it will get downloaded 50k times or more to our own equipment. In the past, we used PHP and just distributed the source to the devices where it ran with the native PHP installation, so the deb files were only a few KB in the end. Now, the company doesn't want source code being distributed, and we've long since moved to NodeJS anyway. vercel/pkg works, but even after the compression in the debian file, the deb ends up 18-19MB.

Does anybody know a good way to bundle the bytecode up in some way that can run directly on a Linux system but have the patched Node binary distributed separately? If we're distributing 5 apps to 50K devices, and everything is running on the same Node 16.x, it seems awfully wasteful to send 5x 18-19MB to each device, and then do that again for each release cycle.

5 comments · 67% upvoted · other discussions

comments

bigujun

Maybe webpack bundle + bytenode can help.

https://github.com/herberttn/bytenode-webpack-plugin

jackdbd

I'm curious. I have never used bytenode. With bytenode you get V8 Ignition bytecode right? So no need to package the Node.js app with pkg, nexe, etc. Right?

Ark42 [OP]

Looks like there's some issues with bytenode and toString(), and the linked thread specifically mentions fast-json-stringify, which we use. I'm also not sure where the node binary comes from in this case? With pkg, the resulting binaries work on all our systems (Ubuntu 14.04 and every release after that, all mixed together..) and these older systems don't even have Node 16 normally available to install separately.

ahoyboyhoy

I think deno packages nicely, though I've not done this myself. Hopefully someone else can chime in. I know it's not Node, but pretty close!

Ark42 [OP]

Deno looks great in general, but I don't think I can just take a node/typescript project and have it work in deno without a bunch of changes.

Ideally, what I'm looking for is maybe just a way to use pkg in a way where it generates two output files instead of one. The patched node binary and the bytecode blob. I could put that node binary into a separate deb and make all the other debs depend on that one. Could even do something in postinst scripts to reassemble the two parts if needed, but I'm not sure if it's even possible.