0.1.3 • Published 10 months ago

remark-mdx-imports v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

remark-mdx-imports

Remark plugin to automatically import exported MDX components.

Content

What is this?

This package is a remark plugin that helps with MDX files.

When should I use this?

If you want to remove technical clutter from your MDX files by pre-defining a set of known JSX components for your MDX files, that you can use without explicitly importing them, then this plugin will add these imports for you.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install remark-mdx-imports

Use

import remarkMdx from 'remark-mdx';
import remarkMdxImports from 'remark-mdx-imports';
import remarkParse from 'remark-parse';
import { unified } from 'unified';

const processor = unified() //
  .use(remarkParse)
  .use(remarkMdx)
  .use(remarkMdxImports);

This markdown:

<Title text="Hello, world!" />

<Hero>
  I **am** a hero!
</Hero>

with this _components.ts file:

export { Hero } from './Hero';
export { Title } from './Title';

would compile without issues, using the exported components from _components.ts automatically.

Options

file?: string

Name of the file to lookup pre-defined component exports.

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago