nitro
nitro copied to clipboard
allow excluding routes from prerenderer crawling
Would be nice if something is intended to be dynamic.
Perhaps we could support prerender.exclude
with RegExp, function or string signature? Or a render hook with option to skip rendering (https://github.com/unjs/nitro/issues/88)?
@pi0 What are your thoughts regarding implementation ? Let me know if I can help :)
Sure makes sense to introduce an option (array) filtering exact URLs for patterns with *
and **
. (I would avoid less explicit fn and regex and hook allows to have advanced context).
(off topic) BTW I can see this is linked to https://github.com/kevinmarrec/nuxt-pwa-module/issues/7. The module should probably use a server handler to generate manifest which then works with nitro :) We can also improve the crawler to avoid overriding already written (public) assets. I wouldn't use feature from this issue for working around.
One thing I do like about the Next implementation is that you can specify on the page component whether it should be prerendered or not. Did you consider something like this on the template or script tag? eg:
<template static>
</template>
This would prevent complex rules that people would have to learn. Maybe even make it work so it applies the setting to any nested pages (for example on a blog page and that all of its article detail pages automatically would have static generation applied)
@chris-visser This is possible to be done using unified route rules to specify group of routes to be static cached (prerenderd)
https://github.com/nuxt/framework/discussions/560
Wauw nice! Have a lot of catching up to do with all of Nuxt 3's features, but honestly great stuff!
Seems like simple string filtering is supported with commit https://github.com/unjs/nitro/commit/a6cbbbe482243a3d8dc4c3917ec406b74fdb2a8f and the prerender.ignore
option. It just seems to be undocumented right now.
I now have a need to exclude all routes except several routes to be prerendered. But plain string prefix won't work for me, neither will routeRules
work (which will cause the index page to be prerendered when in SSR mode). I've already made a PR for that.
Just started testing pre-rendering and route rules but they do not feel intuitive to me, especially when crawling is on it means I have to duplicate route logic. Thoughts on using routeRules
for matching routes to prerender instead of having a separate ignore
option?
E.g. to prerender articles: routeRules: { '/articles/**': { static: true } }
I believe this is possible with routeRules and prerender:false
:
routeRules: { '/articles/**': { prerender: false } }
- We have
predenrer:routes
in order to extend via hook