nuxt-modules / sitemap

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
https://nuxtseo.com/sitemap
335 stars 30 forks source link

Sitemap is not generated on nuxt build #151

Closed rcluis closed 1 year ago

rcluis commented 1 year ago

Describe the bug

This is my sitemap configuration:

sitemap: {
    exclude: [
      'aviso-legal',
      'politica-de-cookies',
      'politica-de-privacidad',
      'terminos-y-condiciones'
    ]
  },

Then I have the site url:

site: {
    url: 'https://...'
  },

When I run nuxt generate it outputs the sitemap properly, but when I run nuxt build the sitemap is not there.

Reproduction

No response

System / Nuxt Info

------------------------------
- Operating System: Darwin
- Node Version:     v20.8.0
- Nuxt Version:     3.7.4
- CLI Version:      3.9.0
- Nitro Version:    2.6.3
- Package Manager:  npm@10.1.0
- Builder:          -
- User Config:      devtools, site, app, modules, sitemap, build, css, vite, vuetify, postcss, runtimeConfig, nitro, content, sourcemap, experimental
- Runtime Modules:  vuetify-nuxt-module@0.5.13, @nuxt/content@2.8.5, nuxt-simple-sitemap@3.4.0
- Build Modules:    -
------------------------------
harlan-zw commented 1 year ago

The sitemap will not be prerendered when you use nuxt build. It will be generated at runtime?

If I'm misunderstanding, then maybe try out the new v4 release and you can clarify further if you still have issues.

JNietou commented 1 year ago

but if you have some pages pre-generated by configuration, I think the ideal is for the sitemap.xml to be created once the build command is run. I'm testing v4 and is the same thing.

I have to run npm run generate to generate the sitemap. Couldn't we have a separate command to generate the sitemap at will?

harlan-zw commented 1 year ago

I don't follow your logic sorry. Why is the ideal to generate it at build time? This would break any sitemap using dynamic URLs. Is there an issue you're facing generating it at runtime?

If you want to prerender it at build just add it to the prerender list

export default defineNuxtConfig({
  nitro: {
    prerender: {
      routes: ['/sitemap.xml']
    }
  }
})
JNietou commented 1 year ago

I understand. In my case in concrete, I have everything generated with statics (prerender) except one route, which is SSR. Therefore, what I expect is that the sitemap of all the static ones is generated except for that specific route.

Don't know if it's the best, but at least it's what I would expect when running the npm run build command.