Purpose
- @mdx-js/react:
The
@mdx-js/react
package focuses on rendering MDX content within React applications. It provides the necessary components and context to handle both Markdown and JSX elements, enabling seamless integration of interactive content within React components. - @mdx-js/mdx:
The
@mdx-js/mdx
package serves as a command-line tool for compiling MDX files. It provides utilities for converting MDX content into various formats, making it suitable for static site generation and other use cases where MDX needs to be processed outside of a React environment. - @mdx-js/loader:
The
@mdx-js/loader
package is designed to integrate MDX processing into Webpack workflows. It transforms MDX files into React components during the build process, allowing developers to import and use MDX content directly in their applications.
Integration
- @mdx-js/react:
@mdx-js/react
is designed for integration within React applications. It works alongside other React components and libraries, making it easy to incorporate MDX content into existing React projects. - @mdx-js/mdx:
@mdx-js/mdx
operates as a standalone tool, independent of any specific build system. This makes it versatile for use in various environments, including static site generators and command-line workflows. - @mdx-js/loader:
@mdx-js/loader
integrates with Webpack, allowing for seamless processing of MDX files as part of the build pipeline. This integration is crucial for projects that rely on Webpack for asset management and bundling.
Rendering
- @mdx-js/react:
@mdx-js/react
provides the rendering capabilities for MDX content within React applications. It handles both Markdown and JSX elements, allowing for dynamic and interactive rendering of MDX files. - @mdx-js/mdx:
@mdx-js/mdx
does not handle rendering directly. Instead, it compiles MDX content into a format that can be rendered by other tools or frameworks, such as React, Vue, or static HTML. - @mdx-js/loader:
@mdx-js/loader
handles the rendering of MDX content indirectly by transforming it into React components. The actual rendering is performed by the React application using the components generated by the loader.
Example Code
- @mdx-js/react:
Example of rendering MDX content with
@mdx-js/react
:import { MDXProvider } from '@mdx-js/react'; import MyMdxContent from './content.mdx'; const App = () => ( <MDXProvider> <MyMdxContent /> </MDXProvider> );
- @mdx-js/mdx:
Example of using
@mdx-js/mdx
from the command line:npx @mdx-js/mdx compile input.mdx -o output.html
- @mdx-js/loader:
Example of using
@mdx-js/loader
in a Webpack configuration:module.exports = { module: { rules: [ { test: /\.mdx$/, use: '@mdx-js/loader', }, ], }, };