@sup39/rehype-mdx-auto-import
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

rehype-mdx-auto-import

A rehype plugin to implicitly import variables in MDX file

Installation

# If you are using yarn
yarn add @sup39/rehype-mdx-auto-import

# If you are using npm
npm install @sup39/rehype-mdx-auto-import

Example

In next.config.mjs:

import mdx from '@next/mdx';
import AutoImport from '@sup39/rehype-mdx-auto-import';

const withMDX = mdx({
  extension: /\.mdx?$/,
  options: {
    rehypePlugins: [
      [AutoImport,
        // import {T, S, C as Code} from '@sup39/mdx-components';
        {
          import: ['T', 'S', {import: 'C', as: 'Code'}],
          from: '@sup39/mdx-components',
        },
        // import * as React from 'react';
        {
          namespace: 'React',
          from: 'react',
        },
        // import React2 from 'react';
        {
          default: 'React2',
          from: 'react',
        },
        // import React3, {useState} from 'react';
        {
          default: 'React3',
          import: ['useState'],
          from: 'react',
        },
      ],
    ],
  },
});
export default withMDX({
  pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
});

Readme

Keywords

none

Package Sidebar

Install

npm i @sup39/rehype-mdx-auto-import

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.32 kB

Total Files

7

Last publish

Collaborators

  • sup39