Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mdx-js/esbuild

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mdx-js/esbuild

esbuild plugin for MDX

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
decreased by-10.97%
Maintainers
4
Weekly downloads
 
Created
Source

@mdx-js/esbuild

Build Coverage Downloads Sponsors Backers Chat

esbuild plugin for MDX.

Contents

What is this?

This package is an esbuild plugin to support MDX.

When should I use this?

This integration is useful if you’re using esbuild (or another tool that uses esbuild).

If you want to evaluate MDX code then the lower-level compiler (@mdx-js/mdx) can be used. to support nonstandard JSX runtime (such as Vue), @mdx-js/mdx can also be used, or our webpack loader (@mdx-js/loader) or Rollup plugin (@mdx-js/rollup).

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/esbuild

yarn:

yarn add @mdx-js/esbuild

Use

Do something like this with the esbuild API:

import esbuild from 'esbuild'
import mdx from '@mdx-js/esbuild'

await esbuild.build({
  entryPoints: ['index.mdx'],
  outfile: 'output.js',
  format: 'esm',
  plugins: [mdx({/* Options… */})]
})

API

This package exports a function as the default export that returns an esbuild plugin.

mdx(options?)

Create an esbuild plugin to compile MDX to JS.

esbuild takes care of turning modern JavaScript features into syntax that works wherever you want it to. With other integrations you might need to use Babel for this, but with esbuild that’s not needed. See esbuild’s docs for more info.

options

options are the same as compile from @mdx-js/mdx with the addition of:

options.allowDangerousRemoteMdx

⚠️ Security: this includes remote code in your bundle. Make sure you trust it! See § Security for more info.

💡 Experiment: this is an experimental feature that might not work well and might change in minor releases.

Whether to allow importing from http: and https: URLs (boolean, default: false).

When passing allowDangerousRemoteMdx, MD(X) and JS files can be imported from http: and https: urls. Take this index.mdx file:

import Readme from 'https://raw.githubusercontent.com/mdx-js/mdx/main/readme.md'

Here’s the readme:

<Readme />

And a module build.js:

import esbuild from 'esbuild'
import mdx from '@mdx-js/esbuild'

await esbuild.build({
  entryPoints: ['index.mdx'],
  outfile: 'output.js',
  format: 'esm',
  plugins: [mdx({allowDangerousRemoteMdx: true, /* Other options… */})]
})

Running that (node build.js) and evaluating output.js (depends on how you evaluate React stuff) would give:

<p>Here’s the readme:</p>
<h1>MDX: Markdown for the component era 🚀</h1>
{/* … */}
<p><a href="https://github.com/mdx-js/mdx/blob/main/license">MIT</a> © …</p>

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 © Titus Wormer

Keywords

FAQs

Package last updated on 14 Dec 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc