I have a Next.js page that is fetching data from a database (using prisma as the ORM) inside of getServerSideProps().
I working based on this example from an official Prisma github. Here is a simplified version of the page setup:
import prisma from 'prisma';
export const getServerSideProps = async ({ req, res }) => {
const drafts = await prisma.post.findMany(...);
};
const MyPage = () => {return <div>Hello</div>};
export default MyPage;
Prisma is imported into the page file and is referenced in getServerSideProps() but is not referenced in the actual page component that is exported. My question is, will prisma be included in the bundle sent to the browser with this page? Or is Next smart enough to trim packages that are referenced only in server-side functions?
No. It will not be bundled to the client side. Next.js is indeed smart enough.
Refer here : https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering