It turns out Prisma doesn't treeshake very well, so your prisma client (20kB compressed) is being imported everytime you use an enum. They also cannot be imported on the client as the prisma client will throw error there.
That's where this generator comes in. It pulls out all your enums into a separate file which you can import without the prisma client being "leaked" in. We managed to reduce the bundle size by 5% across the board on cal.com by using this. (PR here)
-
In your prisma folder, create a generator as above, and add it in your schema file. I use
tsx
to run the generator but you can use ts-node as well (as the PR above do too). -
When you run
prisma generate
, a new file will be created inenums/index.ts
which will contain all your enums. -
Start moving all your imports to use this new entrypoint:
- import { SchedulingType } from "@prisma/client";
+ import { SchedulingType } from "./prisma/enums";
Done! Here is a summary of the results we got: