-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise pkg
bundling so that it is not bundling useless markdown files (combine with esbuild?)
#23
Comments
pkg
bundling so that it is not bundling useless markdown filespkg
bundling so that it is not bundling useless markdown files (combine with esbuild?)
If we are going to integrate a bundler like |
I'm also curious about The only other alternative would be to patch the require/import calls so that can load in-memory chunks from the executable and present them as files. |
The bundler can do things like minification and obfuscation in front of It's important for us to keep track of all assets that may be read dynamically and configure them in a central place. This includes any JSON (tsc deals with this already?), protobuf, object files (for native addons), text files (like certificates)... etc. Web apps also have CSS and images, but these are a separate concern. |
It would be good for the debugging process if the CI/CD process can produce a report/diagram for what will exist in the bundle and its layout structure. The bot can take that and produce nice visuals. |
The lack of support for ESM modules is also concerning. Right now we have a problem with pkg bundling the |
Issue relating to this is here. |
Trying out nextjs on Polykey-Enterprise as its a web application. Interestingly it doesn't use esbuild. It has its own special bundler called Turbopack written in Rust. Funny how we end up writing these things in Rust to support TypeScript applications. Esbuild may still be relevant for Polykey though - specifically for Polykey-CLI and Polykey-Desktop. Because this repo Polykey will focus on staying as a library, so we will move pkg and esbuild and all the other stuff out of Polykey repo. Instead Polykey-CLI will do the bundling into a CLI executable, while Polykey-Desktop will do other bundling specific for Electron. That will reduce the amount of build CI complexity for Polykey, and speed up builds for Polykey-CLI. |
This might be relevant https://esbuild.github.io/api/#keep-names. Cross posting this MatrixAI/TypeScript-Demo-Lib#32 (comment) |
Compare with https://github.com/vercel/ncc. |
Moving this to |
This is done now with esbuild so PKG is alot more optimal. Still needs improvements on our native add-on structure, MatrixAI/js-quic#71 but this issue is done. |
Specification
The
pkg
bundling appears to be bundling useless markdown files. There is a lack of an ignore configuration that we can apply topkg
so that useless markdown files are not packaged as well. Theassets
andscripts
are "inclusive" configuration, we need "exclusive" configuration.This should reduce our file size by quite a bit. On top of that, we should be applying minification to our JS that is being bundled.
One way to solve this, is to make use of a JS bundler first, before using
pkg
. See the problem is thatpkg
is a fairly basic bundler, focused on creating a usable executable. But it's not a good "module bundler", and there are better tools to do module bundling.Suppose we were to combine
esbuild
(or webpack or rollup) withpkg
, whereesbuild
runs first to package the executable into 1 JS file while doing minification. Thenpkg
only has to deal with that 1 file.However we still need to consider things that actually cannot be bundled into that 1 JS file. These are all the assets like images, native addons, JSON configuration files, protobuf files. Furthermore there's also scripts. In the case of module bundling, some of these can be "redirected" like JSON. Others however must remain as actual files on the filesystem. This is where
pkg
can come in save the day. It just needs to maintain its virtual filesystem, and we just need to configure theassets
andscripts
appropriately.So right now the
scripts/pkg.js
is just the beginning. Once a module bundler is involved, the generation of thepkg
configuration JSON is likely to become more complex to deal with all these other assets.Additional context
pkg
bundling files likeCHANGELOG.md
ncc
project, can it also be used in place ofesbuild
?Tasks
The text was updated successfully, but these errors were encountered: