Home > Enterprise >  how to make a standalone build when using nextJS?
how to make a standalone build when using nextJS?

Time:10-05

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.

CodePudding user response:

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

CodePudding user response:

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

  • Related