小编Tri*_*123的帖子

如何分部分导出大型 Next.js 静态站点?

我在我的网站上使用 Next.js Static HTML Export,该网站有 1000 万个静态页面,但在构建应用程序时遇到了内存问题。

是否有可能将其分部分导出,例如第一个版本中的 100k 页,然后是第二个版本中的 100k 页,依此类推?

我不想使用Incremental Static RegenerationgetServerSideProps削减成本。

该网站使用 MongoDB 只有两个页面主页和帖子页面:

index.js
[postPage].js
Run Code Online (Sandbox Code Playgroud)

在主页中我使用了这段代码:

export async function getStaticProps() {
  const { db } = await connectToDatabase();

  const postsFeed = await db
    .collection("myCollection")
    .aggregate([{ $sample: { size: 100 } }])
    .toArray();

  return {
    props: {
      postsFeed: JSON.parse(JSON.stringify(postsFeed)),
    },
  };
}
Run Code Online (Sandbox Code Playgroud)

在帖子页面中我使用了以下代码:

export async function getStaticPaths() {

  const { db } = await connectToDatabase();
  const posts = await db
    .collection("myCollection") …
Run Code Online (Sandbox Code Playgroud)

javascript node.js reactjs next.js

10
推荐指数
1
解决办法
864
查看次数

标签 统计

javascript ×1

next.js ×1

node.js ×1

reactjs ×1