delucis / astro-auto-import

Auto-import components in Astro projects
89 stars 2 forks source link

Only inject imports for components actually used in MDX #43

Open Marocco2 opened 1 year ago

Marocco2 commented 1 year ago

Currently if I use astro-embed-integration in astro.config.mjs it will inject itself (CSS and JS) post compiling to every MDX file, even if there aren't any embeds in the MDX. I propose to check for every file which would got embeds and inject proper astro-embed plugin for each of them

vasfvitor commented 10 months ago

any ideas as how to do it? maybe it should be implemented in auto-import then pass the path/files list from here?

also, couldn't this (import in every mdx) be opt-in?

delucis commented 6 months ago

Transferred this across from https://github.com/delucis/astro-embed as this functionality, if ever implemented, would likely need to be implemented here in astro-auto-import.

I haven’t looked into if this is possible reliably. Perhaps if we could enforce somehow a plugin to run last, it could check the final AST for references and only add import statements for the imports that are needed. Doing it earlier would mean astro-auto-import could miss component usage added by later plugins.