Prerender Ignore Wildcard Path

I have a static nuxt site that uses environment variables that are tokenised into the application during build. On deployment we replace these tokens resulting in no rebuild on deploy. The tokens look like: __VITE_SOMETHING__, they are used for some links on the site. During static build nuxt will traverse these and I get:
Errors prerendering:
[nitro] ├─ /__VITE_SOMETHING__ (159ms)
│ ├── Error: [404] Page not found: /__VITE_ID_REDIRECT_URL__
Errors prerendering:
[nitro] ├─ /__VITE_SOMETHING__ (159ms)
│ ├── Error: [404] Page not found: /__VITE_ID_REDIRECT_URL__
I have tried: 1. Marking NuxtLink's as external 2. Adding to my routeRules the following:
routeRules: {
'/__VITE**': { prerender: false },
'/**': { prerender: true },
},
routeRules: {
'/__VITE**': { prerender: false },
'/**': { prerender: true },
},
But neither seem to work. Is there a way to tell nuxt to ignore a wildcarded path during static compile?
4 Replies
joe_black_unlucky
I'm not sure about your setup but I do a similar thing, I build the complete application and then just do a string replace in dist/server/index.mjs during my staging rollout. This way I can deploy to staging without rebuilding it for staging and replace the api urls with staging api's Works great so far You could do the same and find those variables in index.mjs, or just search your whole dist folder for those variable names
cmcnicholas
cmcnicholasOP3mo ago
I do very similar, the issue I have is that nuxt likes to crawl the links during static generation and it see's links like /__VITE_something__ because the build has no values set (intentional so they can be replaced) I'm trying to tune how nuxt decides to crawl, I'm having to be explicit in routeRoules at the moment e.g.
routeRules: {
'/__VITE_SOMETHING__': { prerender: false },
'/__VITE_SOMETHING_ELSE__': { prerender: false },
'/**': { prerender: true },
},
routeRules: {
'/__VITE_SOMETHING__': { prerender: false },
'/__VITE_SOMETHING_ELSE__': { prerender: false },
'/**': { prerender: true },
},
but would prefer to do for maintenance sake:
routeRules: {
'/__VITE_**': { prerender: false },
'/**': { prerender: true },
},
routeRules: {
'/__VITE_**': { prerender: false },
'/**': { prerender: true },
},
joe_black_unlucky
Are those /__VITE_SOMETHING__ files? And you just using it as token for variable urls? Why dont use use nuxt's runtimeConfig? https://nuxt.com/docs/guide/going-further/runtime-config
Nuxt
Runtime Config · Nuxt Advanced
Nuxt provides a runtime config API to expose configuration and secrets within your application.
joe_black_unlucky
That's where I set my variables Do you want nuxt generate to crawl dynamic links? Then you can set that up in the nuxt config as well You can try and control the prerendering routes list with a hook, we used to do that to add dynamic routes
hooks: {
async 'nitro:config' (nitroConfig) {
const countries = getListOfCountriesGql();
countries.forEach((x) => {
nitroConfig.prerender.routes.push(`/en/a/${x}`);
nitroConfig.prerender.routes.push(`/de/a/${x}`)
});
}
},
hooks: {
async 'nitro:config' (nitroConfig) {
const countries = getListOfCountriesGql();
countries.forEach((x) => {
nitroConfig.prerender.routes.push(`/en/a/${x}`);
nitroConfig.prerender.routes.push(`/de/a/${x}`)
});
}
},
Also comes to mind, if you have a <NuxtLink /> in your application for these token urls, try adding external to the NuxtLink tag
Want results from more Discord servers?
Add your server