Do i just need to run `nuxt generate` without setting `target: static` to build an SSG in Nuxt 3?

Viewed 44

In the Official Guide it says that If to generate a static site, there are two ways:

  • Prerendering (Which is to my understanding is SSG: By running nuxt generate.
  • Client-Only Rendering (SPA): By setting ssr: false and running nuxt generate.

So is nuxt generate a shortcut and it just sets target to static so that I don't have to do it manually in the nuxt.config? I tried using the command with and without setting target: static and it produced the same output but not sure if there are any caveats.

Nuxt Official Docs

1 Answers

At the end, there is no specific reason of having an SPA with a Node.js server, so nuxt build is irrelevant in this case.
Having as SSG or SSR depending on the script that you use seems logical indeed.

Before, we need to have:

  • ssr: true and target: 'server' then run nuxt build
  • ssr: true and target: 'static' then run nuxt generate

It looks more logic to only have the launched script by nuxt deciding that and this is what the team apparently took as a final approach.

So no, I don't think that there are any kind of drawbacks to that. It's mainly a better/faster DX.

PS: if you put target: 'server' but use nuxt generate, you still have the whole thing generated for a static deploy.

Related