How do you accomplish worker code splitting?

I'm trying to write a monolithic worker that handles multiple routes. I would like to dynamically import handler for each route using code splitting. Using the built-in wrangler bundling did not split the bundle at all. I tried building with vite for code splitting, and then using no_bundle, but wrangler will only upload the main chunk. I tried adding a rules field to the wrangler.toml file, but it doesn't seem to have any effect. What am I missing?
2 Replies
Shakeskeyboarde
ShakeskeyboardeOP10mo ago
My wranger.toml looks like this:
name = "cloudflare-worker-test"
compatibility_date = "2024-03-05"
main = "dist/index.js"
no_bundle = true
rules = [{ type = "ESModule", globs = ["dist/**/*.js"] }]
name = "cloudflare-worker-test"
compatibility_date = "2024-03-05"
main = "dist/index.js"
no_bundle = true
rules = [{ type = "ESModule", globs = ["dist/**/*.js"] }]
dmaretskyi
dmaretskyi3mo ago
+1 we also need this
Want results from more Discord servers?
Add your server