nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.16k stars 507 forks source link

fix: `vercel_edge` enable code splitting by default #2812

Closed oscartbeaumont closed 1 day ago

oscartbeaumont commented 1 week ago

❓ Type of change

πŸ“š Description

Previously when building using the vercel_edge preset the entire function code would be exported as a single JS file at .vercel/functions/__nitro.func/index.mjs. This means all dyanmic import's are flattened to be inline.

This change copies the rollup configuration from the Cloudflare preset to the Vercel edge preset so this is no longer the case and dynamic imports actually lazily import code.

This changes allows me to lazy load less important code instead of requiring it all to be loaded and parsed at server startup.

This change aligns the vercel_edge preset with Nitro's existing Cloudflare presets which seems logical because Vercel's Edge functions run on Cloudflare Workers.

πŸ“ Checklist

pi0 commented 1 day ago

First thanks for PR.

Vercel edge, is not based on cloudflare CDN.

I have tested your PR against our e2e deployments (commit: https://github.com/unjs/nitro-deploys/commit/fb1f640e1f04edbeca131f9f81a339f4e098c971)

It seems they don't support dynamic imports (at least via this change alone)

image

I will try to reach out to them for more info (feel free to open a tracker issue) but in the meantime it is not possible at is seems.