Description
Specification
The pkg
bundling appears to be bundling useless markdown files. There is a lack of an ignore configuration that we can apply to pkg
so that useless markdown files are not packaged as well. The assets
and scripts
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 that pkg
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) with pkg
, where esbuild
runs first to package the executable into 1 JS file while doing minification. Then pkg
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 the assets
and scripts
appropriately.
So right now the scripts/pkg.js
is just the beginning. Once a module bundler is involved, the generation of the pkg
configuration JSON is likely to become more complex to deal with all these other assets.
Additional context
- WIP: Demonstrating Native Addons TypeScript-Demo-Lib#38 (comment) - initial detection of
pkg
bundling files likeCHANGELOG.md
- https://github.com/vercel/ncc - vercel also works on the
ncc
project, can it also be used in place ofesbuild
?
Tasks
- ...
- ...
- ...