Comment by curtisblaine
7 hours ago
I'm always curious of the use case when someone proposes Node code bundling. What's the advantage? Obfuscation in SEA?
7 hours ago
I'm always curious of the use case when someone proposes Node code bundling. What's the advantage? Obfuscation in SEA?
In my experience the bundling isn’t really the important aspect (though it also doesn’t harm anything), it’s more just having an ecosystem of plugins for code transpiling, static asset inclusion (e.g. text files) etc and a configuration format folks are already used to.
For me, the main benefit is deployment bundle/artifact size reduction. Mostly from dropping unneeded files from node_modules. Many packages include both esm and cjs builds, sources, docs, TS types, etc. stuff that you don’t need in prod. This matters for lambdas, for example, because deployed code size has limits there.
Running typescript without compilation is still tricky with plain Node. `vite dev` has amazing DX not available for Node programs. I'm wondering if Vite+ tackles this problem.
Don't we have `tsx` and `nodemon` (or the native Node reloader) for that? What are the DX gaps you see on the server side out of on-the-fly transpilation and reload on watch?
Yes, I use tsx for Node programs. It's not great when sharing the same codebase for both client and server code, they have completely different dev workflows.
One advantage of precompilation is risk reduction. Say tsx gets hacked somehow (hardly unprecedented with Node modules!) you’ve got it running on your production server exposed to the internet. Precompilation on a CI pipeline is still a risk but a significantly lower one.
1 reply →
In theory, typescript doesn't need to be transpiled, you can run ts files using `node --experimental-strip-types file.ts` as long as you don't use any code that needs transpilation (like typescript enums).
Still need tsx to do type checking
4 replies →
@afavour if you need precompilation in CI can't you simply use... tsc?
In cases where startup time matters and you have a slow disk, bundling can drastically reduce the number of filesystem calls you have to make for large dependency graphs.
I’ve found if you want interop ts esm and js cjs you need to compile your code - and then `tsc` doesn’t bundle your dependencies for you and outputs incomplete code.