packaging improvements
See original GitHub issueHi ✋ Whilist using kv-asset-handler
I’ve seen some points of improvement worth to share. Would be happy to discuss on each, making sub-issues or going with some PRs to address.
Unnecessary files published inside npm package
Checking unpkg files like tsconfig.json
or .github
are published which increase install size. You may use files
field in package.json to whitelist only dist
(or also src
)
Legacy dist
I can understand that cloudflare workers support (at least partial) of ES6 so we may keep things like await
syntax which may help reduce final worker size (and probably more v8 optimization by using modern syntax). Using tsc
, you may use ESNext
but also careful not using unsupported features like optional chaining. Or using a modern tool like siroc (/cc @danielroe) or directly esbuild. (benefit of using siroc would be to also generate .mjs
output that allows final compiler to do better tree-shaking, publishing public types.
Using full version of mime
mime
has a lite
entry (25 kB vs 9 kB) which is containing all of standard mimes. This can significantly reduce bundle size. You may import from mime/lite
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:13 (6 by maintainers)
Top GitHub Comments
I don’t think performance is a consider when using async/await vs Promise. It won’t have any noticeable impact in your worker. I would privilege the one that’s easier to write/maintain.
On the other hand size is a concern, webpack should be able to swap out mime full for the lite version at build time. I’m concerned that using the lite version by default would break existing users.
Yes, I do agree on the polyfill for
async/await
is not necessary since Cloudflare Workers already provides the support for it. But IMHO I preferkv-asset-handler
to be written in traditional Promise instead ofasync/await
: although v8 improves the performance ofasync/await
quite a lot, it is still slower than traditional Promise.Although full
mime
is a bit large, the bundle size will not affect so much since Cloudflare has the1 MiB
size limit for the script.