我在我的网站上使用 Next.js Static HTML Export,该网站有 1000 万个静态页面,但在构建应用程序时遇到了内存问题。
是否有可能将其分部分导出,例如第一个版本中的 100k 页,然后是第二个版本中的 100k 页,依此类推?
我不想使用Incremental Static Regeneration或getServerSideProps削减成本。
该网站使用 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)