-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Is your feature request related to a problem? Please describe.
I'd like to be able to tell Vite/Rollup about .html
generation dependencies so it recognizes additional files as part of the dependency graph for determining what needs to be rebuilt when a file changes. I'm using a Nunjucks environment to render input files on the fly in transformIndexHtml
, and that's working great! But there's no way to tell Vite that additional template files are important to a given HTML input and should be considered full-reload
triggers.
Describe the solution you'd like
Unless Vite significantly alters the Rollup contract and makes this impossible, my hunch (and Rich's 😉) is that being able to declare a new file to watch via Rollup's this.addWatchFile
could in theory pull it off. I don't need Vite to do anything with it — I just need it to know "whatever it means to invalidate index.html
trust it has been invalidated because I told you _layouts/base.html
changing matters."
But this appears to be currently impossible because you do not have access to the current PluginContext
at that time because we're nested within the HTML plugin's own transform
call.
Describe alternatives you've considered
I've been able to hack this via handleHotUpdate
and externally tracking the dependency files, but it would be nice to lean on the existing infrastructure if possible.
handleHotUpdate({ file, server }) {
// not perfect, but if any Nunjucks dependency changes just invalidate
// all the HTML so the reload can trigger a rebuild
if (templateDependencies.has(file)) {
server.ws.send({
type: "full-reload",
file: "*",
});
return [];
}
},
Thank you! 🎉