11ty / eleventy-plugin-vite

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

sitemap.xml not being processed correctly #17

Closed andystevenson closed 1 year ago

andystevenson commented 1 year ago

If a sitemap.xml is generated as part of an 11ty build the plugin fails. Works fine in dev.

I created a simple hello-world example in https://github.com/andystevenson/11ty-plugin-vite-sitemap-issue

The build fails with ...

[rollup-plugin-dynamic-import-variables] Unexpected token (1:0)
file: /Users/andystevenson/11ty-plugin-vite-sitemap-issue/.11ty-vite/sitemap.xml:1:0
[11ty] Encountered a Vite build error, restoring original Eleventy output to _site SyntaxError: Unexpected token (1:0)

It looks like sitemap.xml is included in list of assets created by 11ty... so automatically being passed to vite build to be transformed by rollup/esbuild.

Looking at the vite config options in the docs I tried adding

assetsInclude: ['**/*.xml']

(commented out in .eleventy.js) to the viteOptions to the plugin within .eleventy.js config... that stops the build crashing but it also still ends up in sitemap.xml being transformed into an empty chunk.

zachleat commented 1 year ago

Howdy! This was fixed by 7cd0709dfaf5b5dda3ccb49146a840669acabcd9 and included with 2.0.0-canary.2. Will ship with 2.0 stable shortly!

benjamingeets commented 1 year ago

Hello,

With @11ty/eleventy 2.0.0 and @11ty/eleventy-plugin-vite 4.0.0, I still can't build my sitemap (which is in nunjucks).

The website builds "normally" but my sitemap.njk seems just to be ignored and doesn't appear on the build.

Am I misunderstanding something or is it a bug? (and thank you for everything you're doing with 11ty, it's really great 🤓)

✅ EDIT: ok, my bad, it appears that i just need to change permalink to /public/sitemap.xml.