Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only inject imports for components actually used in MDX #43

Open
Marocco2 opened this issue Jul 22, 2023 · 2 comments
Open

Only inject imports for components actually used in MDX #43

Marocco2 opened this issue Jul 22, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Marocco2
Copy link

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

@delucis delucis added enhancement New feature or request help wanted Extra attention is needed labels Jul 22, 2023
@vasfvitor
Copy link

vasfvitor commented Nov 26, 2023

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 delucis transferred this issue from delucis/astro-embed Apr 4, 2024
@delucis delucis changed the title (SSG) astro-embed-integration should inject itself only when MDX has embeds Only inject imports for components actually used in MDX Apr 4, 2024
@delucis
Copy link
Owner

delucis commented Apr 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants