
Product
Introducing GitHub Actions Scanning Support
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.
@astro-m2dx/vite-astro-mdx-mapping
Advanced tools
Remark plugin to add automatic component mapping to MDX files
DEPRECATED: Please consider using the plugin astro-m2dx, which bundles all features from the different
@astro-m2dxplugins in one plugin (all features are opt-in).
Vite plugin to define common component mappings for all Astro markdown files in a directory.
This package is a Vite plugin to add support for automatic components mapping insertion to markdown-files in the context of Astro site generation.
In Astro you can define a mapping from HTML elements to JSX components by exporting const components = { ... } in any MDX file. With this plugin you can define this per directory.
If you want to use the same component mapping for all MDX-files within a directory and its subdirectories and want to keep your markdown files and their frontmatter as clean as possible.
This package is ESM only.
In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
npm install -D @astro-m2dx/vite-astro-mdx-mapping
In your astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import mdxMapping from '@astro-m2dx/vite-astro-mdx-mapping';
// ^^^
// https://astro.build/config
export default defineConfig({
integrations: [mdx()],
markdown: {
remarkPlugins: [],
extendDefaultPlugins: true,
},
vite: {
plugins: [mdxMapping()],
// ^^^
},
});
This uses the default options, where the name of the mapping file is _mdx-mapping.ts.
Now create a TypeScript/JavaScript file, that exports a components object mapping HTML elements to arbitrary Astro, React, ... components.
import { Title } from '@components/Title';
export const components = {
h1: Title,
};
If you want to use a different name for the mapping file, you can specify it in the plugin's name option like so:
plugins: [mdxMapping({name: "_components.ts"})],
FAQs
Remark plugin to add automatic component mapping to MDX files
The npm package @astro-m2dx/vite-astro-mdx-mapping receives a total of 9 weekly downloads. As such, @astro-m2dx/vite-astro-mdx-mapping popularity was classified as not popular.
We found that @astro-m2dx/vite-astro-mdx-mapping demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.

Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.

Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.