#how build project to one bin?
17 messages · Page 1 of 1 (latest)
there's almost zero reason to do this but you can look into yao-pkg or SEA
bun build or deno compile. Node.js' SEA only works for CommonJS input and the last time I checked still expects the source files to be on the file system.
More practically you might want to look into Dockerizing it instead, if you want an artifact to move around
i have api server for project and i didnt want share source code yea i know 100% no way to secure
Worrying about source code sharing is IMHO a waste of time. Instead put into contracts the protections instead.
Anyone who really wants to know what you're doing will find out if you let them have access to it. Especially JS and other interpreted languages.
SEA is the recommended way of building single binary Node.js apps. Sourceless bins are not supported by SEA at the moment but I'd be happy to implement it if the development is funded. Yao-pkg does support sourceless bins by relying on just the V8 code cache without sources but it's not 100% secure: https://swarm.ptsecurity.com/how-we-bypassed-bytenode-and-decompiled-node-js-bytecode-in-ghidra/. Note that the sourceless feature of yao-pkg on the latest versions of Node.js is blocked - https://github.com/yao-pkg/pkg/issues/87 which I was looking into earlier but I can't justify more time for that without the proper funding
SEA cannot be "the recommended way" when it is both experimental and lacking in features
the issue you linked also appears to be limited to cross-platform building?
Node.js' SEA only bundles CommonJS. Not even close to the capability of deno compile.
Here's a gist re compiling to a single executable using modern JavaScript runtimes Compiling a standalone executable using modern JavaScript/TypeScript runtimes https://gist.github.com/guest271314/c9543a19d8ccf72881355b27d0107551
There's also Bellard's QuickJS qjsc, QuickJS NG's qjs with built in compilation capability, Facebook's Static Hermes to compile JavaScript to a native executable, Bytecode Alliance's javy to compile JavaScript to WASM - with WASI support. And other ways to compile JavaScript to a standalone executable.
Node.js SEA lags far behind deno compile for capabilities. SEA is still stuck exclusively in CommonJS world.
You can use esbuild to bundle your source into one big JS file (instead of shipping many small source files).
You can minimize/uglify the bundle to make it weigh less and also be less readable, using the same tool
There are also libraries that let you bundle that along with a NodeJS distributable into a single executable (.exe)
like: https://www.npmjs.com/package/pkg