Tree-shaking for Pages Function
I've got a codebase tested with Vitest, exclusively using in-source testing (https://vitest.dev/guide/in-source.html). When building the front-end application,
import.meta.vitest
is defined as "undefined"
so the tests get eliminated by the bundler. This doesn't seem to work with Pages Functions. When I import modules that have little source code but massive tests, it seems like the content of the tests gets included, cause the build will fail with the message Error: Failed to publish your Function. Got error: Your Functions script is over the 1 MiB size limit (workers.api.error.script_too_large)
. Is there any way to tree-shake exported handlers? (My current workaround is adding a script to the build step that builds a second time with routes as entrypoints, then moves them to the functions directory. Would really like to avoid this.)0 Replies