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:
I have tried:
1. Marking NuxtLink
's as external
2. Adding to my routeRules
the following:
But neither seem to work.
Is there a way to tell nuxt to ignore a wildcarded path during static compile?4 Replies
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 namesI 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.
but would prefer to do for maintenance sake:
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-configNuxt
Runtime Config · Nuxt Advanced
Nuxt provides a runtime config API to expose configuration and secrets within your application.
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
Also comes to mind, if you have a <NuxtLink /> in your application for these token urls, try adding
external
to the NuxtLink tag