Using defineBasicLoader
only for build time with Nuxt + Static generation
#599
-
Hello, I am making a website with Nuxt. The website is static. All the data I need can be fetch at build time, not runtime fetching. I was reading the Data Loaders and see if this library solve my issues. I think I can use a const basicLoaderOptions: DefineDataLoaderOptions_DefinedData = {
// We do want to run it on the server (e.g. at build time for static site)
server: true,
// Make the loader "lazy" on the client so it DOES NOT re-fetch
// after hydration:
lazy: () => !import.meta.env.SSR
} Is this the right approach? More concrete example:export const useApps = defineBasicLoader(async () => {
const { client } = usePrismic()
const apps = await client.getByType<AppDocument>('app')
if (!apps.results.length)
throw new Error('No apps data from Prismic!')
return apps
}, {
server: true,
lazy: () => !import.meta.env.SSR,
}) Typescript issuewith the current object The documentation states that this option can also be Thanks for this amazing library and all the work with Pinia & Pinia Colada. I am very excited to start using these new versions. Amazing job! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
After reading all the documentation: Data loaders, Pinia Colada and Nuxt composables here is my conclusion:
I would appreciate if you share you thoughts about this. PS: Maybe this can be a page in a documentation somewhere, when to use what. With the amount of options available, it is a bit hard for beginners to identify each use case :) |
Beta Was this translation helpful? Give feedback.
-
Hello! Thanks for the feedback, it's really useful. The type you are using is specifically for when the |
Beta Was this translation helpful? Give feedback.
Hello! Thanks for the feedback, it's really useful.
The type you are using is specifically for when the
data
property cannot be undefined so it's not possible to pass true. The actual type of options is a union of the different possibilities (DefineDataLoaderOptions_LaxData | DefineDataLoaderOptions_DefinedData
currently)