kit
kit copied to clipboard
adapter-cloudflare generates very inefficient _routes.json which hits rules limits
Describe the bug
@sveltejs/adapter-cloudflare generates a quite inefficient _routes.json while cloudflare pages can only handle up to 100 rules. This ends up with this kind of warning:
Function includes/excludes exceeds _routes.json limits (see https://developers.cloudflare.com/pages/platform/functions/routing/#limits). Dropping 67 exclude rules — this will cause unnecessary function invocations.
For instance, the below directory structure:
static/images/{a,b,c,d,e}.png
static/fonts/{a,b,c,d,e}.otf
...
will list individual files and result into the below _routes.json exclude
images/a.png
...
images/e.png
fonts/a.otf
...
fonts/e.otf
while you'd expect some wildcards instead
images/*
fonts/*
Reproduction
add lots of files to a folder static/folder1
Logs
No response
System Info
System:
OS: Windows 10 10.0.22621
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 14.95 GB / 31.80 GB
Binaries:
Node: 16.16.0 - ~\AppData\Local\pnpm\node.EXE
Yarn: 1.22.19 - ~\AppData\Local\pnpm\yarn.CMD
npm: 8.11.0 - ~\AppData\Local\pnpm\npm.CMD
Browsers:
Chrome: 111.0.5563.147
Edge: Spartan (44.22621.1485.0), Chromium (111.0.1661.62)
Internet Explorer: 11.0.22621.1
npmPackages:
@sveltejs/adapter-auto: 2.0.0 => 2.0.0
@sveltejs/adapter-cloudflare: 2.2.0 => 2.2.0
@sveltejs/kit: 1.15.2 => 1.15.2
svelte: ^3.58.0 => 3.58.0
vite: ^4.2.1 => 4.2.1
Severity
annoyance
Additional Information
No response
Does the exclude option mentioned here help? https://kit.svelte.dev/docs/adapter-cloudflare#options
Worked for me. You can set pre-defined wildcard excludes.
I used this as a workaround as well.
Now, I don't see any reason why the generated _routes.json for static folder should not use wildcard instead of listing files 1 by 1
I just hit the same problem where on my small site /static folder was generating way too much rules in exclude block.
Why isn't /static/* the default?
I made a PR #10345 . I hope it goes in the right direction🥰
Same issue, hope this is merged!
Now, I don't see any reason why the generated
_routes.jsonfor static folder should not use wildcard instead of listing files 1 by 1
I just hit the same problem where on my small site /static folder was generating way too much rules in exclude block.
Why isn't
/static/*the default?
The files in /static are always copied to the root folder of the build. Hence your /static/favicon.png file actually resolves to /favicon.png. Since they live at the root, we can't just mark it with a wildcard because that would make all routes static.