prerender
Guides > Pre-rendering (SSG) explains what pre-rendering is and how to use it.
By default, pre-rendering is disabled. To enable it:
Toggle
In some situations, a page shouldn't be pre-rendered. For example a news page that displays the latest news fetched from a database should be rendered at request-time and certainly not at build-time.
Guides > Pre-rendering (SSG) explains in depth whether a page should be pre-rendered or not.
You can use prerender: false
to tell Vike to skip a page from pre-rendering.
Different defaults
You can define prerender
in higher levels so it applies to more/all pages.
This is especially handy with Domain-Driven File Structure:
You can also make pre-rendering opt-in instead of opt-out:
Conditional pre-rendering
You can pre-render pages conditionally:
This is useful for previewing CMS pages (you don't want to pre-renderer a CMS deploy preview).
Note that onBeforePrerenderStart()
hooks are always called, even if prerender
is false
.
If you want to call onBeforePrerenderStart()
hooks conditionally as well:
Settings
partial
boolean
(default: false
)
Allow only some of your pages to be pre-rendered.
This setting doesn't affect the pre-rendering process: it merely suppresses the warning that some pages aren't pre-rendered.
As explained in Guides > Pre-rendering (SSG), if you don't pre-render all your pages then you need a production server.
That said, if you cannot or don't want to pre-render all your pages while still deploying to a static host, then see the workaround at #1476 - Pre-rendered dynamic routes (static host deployment).
Also, by using
vite-plugin-vercel
, you can statically deploy your pre-rendered pages while using a production server for your non-pre-rendered pages.
Vike shows a warning that a page cannot be pre-rendered when the page has a parameterized route (e.g. a Route String
/movie/@movieId
, or a Route Function) while there isn't anyonBeforePrerenderStart()
hook that provides at least one URL matching the page's route (e.g./movie/42
).
noExtraDir
boolean
(default: false
)
Don't create a new directory for each HTML file.
For example, generate dist/client/about.html
instead of dist/client/about/index.html
.
Generating a directory for each HTML file is the most reliable way for telling Static Hosts the static URL of each static HTML. But some static hosts prefer the other way.
parallel
boolean | number
(default: os.cpus().length
)
Number of concurrent pre-render jobs.
Set to false
(or 1
) to disable concurrency.
The default value is the fastest, but it may induce high spikes of memory usage.
Disable concurrency if:
- You encounter
JavaScript heap out of memory
errors.- If pre-rendering takes an abnormal high amount of time. (Caused by the very slow process of memory swapping that kicks-in when memory starts to saturate).
disableAutoRun
boolean
(default: false
)
When running $ vite build
, Vike automatically triggers pre-rendering. (If you enabled it.)
You can disable the automatic triggering:
You can then manually trigger pre-rendering using:
See also disableAutoFullBuild
.