🚀 DAY 4 OF LAUNCH WEEK: Introducing GitHub Actions Scanning Support.Learn more →
Socket
Book a DemoInstallSign in
Socket

@astro-m2dx/vite-astro-mdx-mapping

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astro-m2dx/vite-astro-mdx-mapping

Remark plugin to add automatic component mapping to MDX files

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
13
44.44%
Maintainers
1
Weekly downloads
 
Created
Source

Astro M²DX - Vite plugin to export component mappings per-directory

DEPRECATED: Please consider using the plugin astro-m2dx, which bundles all features from the different @astro-m2dx plugins in one plugin (all features are opt-in).

Vite plugin to define common component mappings for all Astro markdown files in a directory.

Content

What is this?

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.

When should I use this?

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.

Install

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

Use

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,
};

Options

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"})],

Keywords

remark-plugin

FAQs

Package last updated on 11 Oct 2022

Did you know?

Socket

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.

Install

Related posts