UNPKG

657 BJavaScriptView Raw
1const {Asset} = require('parcel-bundler')
2
3const mdx = require('@mdx-js/mdx')
4
5class MDXAsset extends Asset {
6 constructor(name, pkg, options) {
7 super(name, pkg, options)
8 this.type = 'js'
9 }
10
11 async generate() {
12 const config = await this.getConfig(
13 ['.mdxrc', 'mdx.config.js', 'package.json'],
14 {packageKey: 'mdx'}
15 )
16 const compiled = await mdx(this.contents, config)
17 const fullCode = `/* @jsx mdx */
18import React from 'react';
19import { mdx } from '@mdx-js/react'
20${compiled}
21`
22 return [
23 {
24 type: 'js',
25 value: fullCode,
26 sourceMap: undefined
27 }
28 ]
29 }
30}
31
32module.exports = MDXAsset