#auto import components

1 messages · Page 1 of 1 (latest)

stray ingot
#

how do I automatically import components into my mdx files?

flat lakeBOT
#

Hi @stray ingot. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Astro and Starlight don’t provide a built-in “auto-import” for components in MDX. You must import components at the top of each .mdx file before using them, e.g.:

import { Card } from '@astrojs/starlight/components';

<Card title="Check this out">Content</Card>

This is the documented usage for components in MDX (install @astrojs/mdx, then import and use components) (Using components in MDX; Starlight components usage).

If you need MDX-wide remapping of HTML elements to custom components (not auto-imports), you can export a components map from the MDX file and pass it through when importing MDX, or define it within the MDX file itself (Custom components with imported MDX; Assigning custom components).

I’m sorry, but the knowledge sources don’t mention an official auto-import integration for MDX components. The Starlight docs show explicit imports per file, and the Astro MDX guide does the same.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@stray ingot Kapa.ai is still learning and improving, please let me know how I did by reacting below.

stray ingot
flat lakeBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

I can’t confirm details about astro-auto-import from the provided knowledge sources. They don’t document an official auto-import feature for MDX; components are shown as explicitly imported in each .mdx file (Using components in MDX; Starlight: Using components).

If you choose to use a third-party solution like astro-auto-import, please refer to its README for setup. Sorry I can’t provide steps from the docs above.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: