最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to make a standalone build when using nextJS? - Stack Overflow

programmeradmin5浏览0评论

I'm working on a project where they chose to use nextJS as a client side tool, but I want to deploy the client as static code somewhere else.

Doing a build creates a folder with all the nextJS proprietary server stuff.

Is there a way to make a normal build to just static react files? I don't want SSR or any of their EEE stuff.

I know Vercel is a VC backed mousetrap, so it's not really in their interest to make it easy to extract yourself, but hoping we don't have to rebuild the site to get out of this.

I'm working on a project where they chose to use nextJS as a client side tool, but I want to deploy the client as static code somewhere else.

Doing a build creates a folder with all the nextJS proprietary server stuff.

Is there a way to make a normal build to just static react files? I don't want SSR or any of their EEE stuff.

I know Vercel is a VC backed mousetrap, so it's not really in their interest to make it easy to extract yourself, but hoping we don't have to rebuild the site to get out of this.

Share Improve this question asked Oct 4, 2022 at 19:19 dcsandcsan 12.3k17 gold badges92 silver badges139 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Update your build script in package.json to use next export:

"scripts": {
  "build": "next build && next export"
}

Note: this feature does not support the following:

  • Image Optimization (default loader)
  • Internationalized Routing
  • API Routes
  • Rewrites
  • Redirects
  • Headers
  • Middleware
  • Incremental Static Regeneration
  • fallback: true
  • getServerSideProps

If you are using any of the features listed above, you will have to stick to prerendering individual pages, which Next automatically does for you.

Source: Docs


UPDATE February 2024: the configuration to for static exports has changed, slightly. Refer to the latest Next.js docs for details.

Sounds like you are looking for the next export. Should do just that, but there are some limitations. Documentation is here: https://nextjs/docs/advanced-features/static-html-export

发布评论

评论列表(0)

  1. 暂无评论