You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@mdx-js/loader

Package Overview
Dependencies
Maintainers
4
Versions
216
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mdx-js/loader

Webpack loader for MDX


Version published
Weekly downloads
630K
decreased by-4.1%
Maintainers
4
Install size
3.82 MB
Created
Weekly downloads
 

Package description

What is @mdx-js/loader?

@mdx-js/loader is a webpack loader for MDX, which allows you to import and use .mdx files as React components. MDX is a format that lets you seamlessly write JSX in your Markdown documents. This package is particularly useful for integrating MDX into your React projects, enabling you to leverage the power of React components within your Markdown content.

What are @mdx-js/loader's main functionalities?

Importing MDX files as React components

This feature allows you to import MDX files as React components, enabling you to use JSX syntax within your Markdown files. The code sample demonstrates how to configure webpack to use @mdx-js/loader and how to use an MDX file within a React component.

```javascript
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.mdx?$/,
        use: [
          'babel-loader',
          '@mdx-js/loader'
        ]
      }
    ]
  }
};

// example.mdx
export const MyComponent = () => <div>Hello, MDX!</div>;

# Hello, world!

<MyComponent />

// App.js
import React from 'react';
import MDXContent from './example.mdx';

const App = () => (
  <div>
    <MDXContent />
  </div>
);

export default App;
```

Customizing MDX components

This feature allows you to customize MDX components by importing and using your own React components within MDX files. The code sample shows how to import a custom React component into an MDX file and use it within the Markdown content.

```javascript
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.mdx?$/,
        use: [
          'babel-loader',
          '@mdx-js/loader'
        ]
      }
    ]
  }
};

// example.mdx
import { MyCustomComponent } from './MyCustomComponent';

# Hello, world!

<MyCustomComponent />

// MyCustomComponent.js
import React from 'react';

export const MyCustomComponent = () => <div>Custom Component Content</div>;

// App.js
import React from 'react';
import MDXContent from './example.mdx';

const App = () => (
  <div>
    <MDXContent />
  </div>
);

export default App;
```

Other packages similar to @mdx-js/loader

Readme

Source

@mdx-js/loader

Build Coverage Downloads Sponsors Backers Chat

webpack loader for MDX.

Contents

What is this?

This package is a webpack loader to support MDX.

When should I use this?

This integration is useful if you’re using webpack (or another tool that uses webpack, such as Next.js).

This integration can be combined with the Babel loader to support nonstandard JSX runtimes (such as Vue) or compile modern JavaScript features to ones your users support.

If you want to evaluate MDX code then the lower-level compiler (@mdx-js/mdx) can be used manually.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install @mdx-js/loader

yarn:

yarn add @mdx-js/loader

Use

Add something along these lines to your webpack.config.js:

module.exports = {
  module: {
    // …
    rules: [
      // …
      {
        test: /\.mdx?$/,
        use: [
          {
            loader: '@mdx-js/loader',
            /** @type {import('@mdx-js/loader').Options} */
            options: {}
          }
        ]
      }
    ]
  }
}

See also ¶ Create React App (CRA), ¶ Next.js, and ¶ Vue CLI, if you’re using webpack through them, for more info.

API

This package exports a webpack plugin as the default export.

Source maps are supported based on how you configure webpack. You do not need to pass options.SourceMapGenerator.

options

options are the same as compile from @mdx-js/mdx.

Note: Babel

If you use modern JavaScript features you might want to use Babel through babel-loader to compile to code that works:

// …
use: [
  // Note that Webpack runs right-to-left: `@mdx-js/loader` is used first, then
  // `babel-loader`.
  {loader: 'babel-loader', options: {}},
  {
    loader: '@mdx-js/loader',
    /** @type {import('@mdx-js/loader').Options} */
    options: {},
  },
];
// …

Types

This package is fully typed with TypeScript. See § Types on our website for information.

An Options type is exported, which represents acceptable configuration.

Security

See § Security on our website for information.

Contribute

See § Contribute on our website for ways to get started. See § Support for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Compositor and Vercel

Keywords

FAQs

Package last updated on 17 Aug 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc