11ty / eleventy-plugin-vite

A plugin to use Vite with Eleventy
134 stars 10 forks source link

Vite does not copy or process sitemap.xml when building #38

Closed aplauche closed 1 year ago

aplauche commented 1 year ago

Using this plugin on a basic site, but a big issue is when creating a sitemap using a sitemap.njk file with the following code:

---
permalink: /sitemap.xml
eleventyExcludeFromCollections: true
---

The sitemap is generated in dev server mode, but when built it is created in the .11ty-vite folder, but vite ignores it and it is not copied into the production build. Looking into vite options to fix this, but figured I would log as an issue as well since this likely is affecting other users too and is a bit tricky to notice since it seems to work fine on dev and does not throw any notices or errors.

aplauche commented 1 year ago

Update - tried using vite-plugin-static-copy, but this also does not work since it copies the sitemap into the final _site folder before vite attempts to generate all the other files. This causes an error.

ngdio commented 1 year ago

I've just encountered this with a robots.txt file. Change your permalink to /public/sitemap.xml and it should be copied to production.

This is intended behaviour since Vite only copies files that are referenced in the website's source code, whereas those files are not. I think it works in the dev server as Vite works in-place there and the original files aren't discarded.

aplauche commented 1 year ago

Ah interesting that makes sense. Thanks for sharing your fix. I'll go ahead and close this - hopefully will be helpful to others in the future though as well.