Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/content/docs/en/guides/integrations-guide/mdx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ const { Content } = await render(entry);
<Content components={{ h1: CustomHeading }} />
```

### Using web components in MDX

If you have a web component defined in a separate JavaScript file, you can include it in your MDX file by importing the script and adding a `<script>` tag with `type="module"`.
The script will be executed on the client side.

```js title="src/web-component.js"
class MyEl extends HTMLElement { ... }
customElements.define('my-el', MyEl);
```

```mdx title="src/Page.mdx"
import webComponent from "./web-component.js?url";

<script src={webComponent} type="module"></script>

<my-el />
```

## Configuration

Once the MDX integration is installed, no configuration is necessary to use `.mdx` files in your Astro project.
Expand Down