NextJS 是否包含仅在包中的 getServerSideProps 中引用的库?
Does NextJS include libraries that are referenced only in getServerSideProps in the bundle?
我有一个 Next.js 页面正在从 getServerSideProps()
.
中的数据库(使用 prisma 作为 ORM)获取数据
我的工作基于 this example from an official Prisma github。这是页面设置的简化版本:
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 已导入到页面文件中并在 getServerSideProps()
中被引用,但在导出的实际页面组件中未被引用。我的问题是,prisma 会包含在与此页面一起发送到浏览器的包中吗?或者 Next 是否足够智能 trim 仅在服务器端函数中引用的包?
没有。它将不会捆绑到客户端。 Next.js确实够聪明
参考这里:
https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering
我有一个 Next.js 页面正在从 getServerSideProps()
.
我的工作基于 this example from an official Prisma github。这是页面设置的简化版本:
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 已导入到页面文件中并在 getServerSideProps()
中被引用,但在导出的实际页面组件中未被引用。我的问题是,prisma 会包含在与此页面一起发送到浏览器的包中吗?或者 Next 是否足够智能 trim 仅在服务器端函数中引用的包?
没有。它将不会捆绑到客户端。 Next.js确实够聪明
参考这里: https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering