Skip to content

Instantly share code, notes, and snippets.

@pi0neerpat
Last active March 3, 2021 02:30
Show Gist options
  • Select an option

  • Save pi0neerpat/21e13b80a55311dc56b80e8c8963b5b4 to your computer and use it in GitHub Desktop.

Select an option

Save pi0neerpat/21e13b80a55311dc56b80e8c8963b5b4 to your computer and use it in GitHub Desktop.
Markdown MDX in Redwood

Installation and setup

yarn rw setup webpack
yarn workspace web add react-markdown @tailwindcss/typography

Now update webpack to load ".md"

// web/config/webpack.config.js

module.exports = (config, { env }) => {
  config.module.rules.push({
    test: /\.(md)$/i,
    use: [
      {
        loader: 'raw-loader',
      },
    ],
  })
  return config
}

And update tailwindcss configs

// web/config/postcss.config.js

module.exports = {
  plugins: [
    // ...
    require('@tailwindcss/typography'),
  ],
}

RESTART your dev server

Place your "text.md" next to your component, Then import it and use it like this:

import ReactMarkdown from 'react-markdown'
import markdownFile from './text.md'

const myComponent = () => {
  return (
    <>
      <ReactMarkdown className="prose" children={`${markdownFile}`} />
    </>
  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment