3.6.0 • Published 10 months ago

vite-plugin-mdx v3.6.0

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

====================== WE ARE LOOKING FOR A NEW MAINTAINER ====================

Vite Plugin MDX

Use this Vite plugin to use MDX v1 with your Vite v2 app. For Vite v3+ we recommend migrating to MDX v2 using the official @mdx-js/rollup, this comment explains how to implement it.

Features:

  • Works with React and Preact.
  • Works with Vue [WIP].
  • HMR support.
  • SSR support.
  • Plugin support, such as remark-frontmatter.

Getting Started

  1. Install:

    1. Vite Plugin:
       npm install vite-plugin-mdx
    2. MDX v1:
      npm install @mdx-js/mdx
    3. MDX React:
      npm install @mdx-js/react
      Or MDX Preact:
      npm install @mdx-js/preact
  2. Add the plugin to your vite.config.js.

    // vite.config.js
    
    import mdx from 'vite-plugin-mdx'
    
    // `options` are passed to `@mdx-js/mdx`
    const options = {
      // See https://mdxjs.com/advanced/plugins
      remarkPlugins: [
        // E.g. `remark-frontmatter`
      ],
      rehypePlugins: [],
    }
    
    export default {
      plugins: [mdx(options)]
    }
  3. You can now write .mdx files.

    // hello.mdx
    
    import { Counter } from './Counter.jsx'
    
    # Hello
    
    This text is written in Markdown.
    
    MDX allows Rich React components to be used directly in Markdown: <Counter/>
    // Counter.jsx
    
    import React, { useState } from 'react'
    
    export { Counter }
    
    function Counter() {
      const [count, setCount] = useState(0)
    
      return (
        <button onClick={() => setCount((count) => count + 1)}>
          Counter: {count}
        </button>
      )
    }

Examples

File-specific options

To define options a per-file basis, you can pass a function to the mdx plugin factory.

mdx((filename) => {
  // Any options passed to `mdx` can be returned.
  return {
    remarkPlugins: [
      // Enable a plugin based on the current file.
      /\/components\//.test(filename) && someRemarkPlugin,
    ]
  }
})

Pre-built transclusion

To embed an .mdx or .md file into another, you can import it without naming its export. The file extension is required. Remark plugins are applied to the imported file before it's embedded.

import '../foo/bar.mdx'
3.6.0

10 months ago

3.5.11

2 years ago

3.5.10

3 years ago

3.5.7

3 years ago

3.5.9

3 years ago

3.5.8

3 years ago

3.5.6

3 years ago

3.5.5

3 years ago

3.5.4

3 years ago

3.5.3

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.4.0

3 years ago

3.5.0

3 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-alpha.1

3 years ago

2.0.0-alpha.0

3 years ago

0.4.1

3 years ago

0.4.0

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago