1 | const {Asset} = require('parcel-bundler')
|
2 |
|
3 | const mdx = require('@mdx-js/mdx')
|
4 |
|
5 | class 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 */
|
18 | import React from 'react';
|
19 | import { 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 |
|
32 | module.exports = MDXAsset
|