mdx-bundler icon indicating copy to clipboard operation
mdx-bundler copied to clipboard

Compiling MDX files from command line.

Open rajuashok opened this issue 3 years ago • 2 comments

Hi there,

I have a very unique use case that I think this library could work for, but I'm unsure based on what I've read so far. Also, sorry if this is not the right place to post a question like this - feel free to redirect me.


I have a single MDX file that is similar to this:

import MultiChoice from './multi_choice.tsx'

Lorem Ipsum <a href={url}>{name}</a>. Lorem Ipsum <MultiChoice options={options}/> stuff.

I'd like to build a script that will take in a list of objects like this...

posts = [
  {
    name: "Some Name",
    url: "www.somename.com",
    options: [
      "Option 1",
      "Option 2",
      "Option 3"
    ]
  }
]

...and output several MDX files with the variables replaced. For example the above object would output a single MDX file like this:

import MultiChoice from './multi_choice.tsx'

Lorem Ipsum <a href="www.somename.com">Some Name</a>. Lorem Ipsum <MultiChoice options={["Option 1", "Option 2", "Option 3"]}/> stuff.

Is something like this possible with your library?

rajuashok avatar Jun 22 '21 17:06 rajuashok

MDX-Bundler could be baked into a command line utility to bundle the mdx but it would throw out .js bundles not updated mdx.

I'd say this is something that could be done with some regex and placeholders in your content. Read in the file, replace _OPTIONS_ with ["Option 1", "Option 2", "Option 3"] and write out the file.

You could use a global variable to pass data to the bundle at runtime.

Arcath avatar Jul 01 '21 08:07 Arcath

I don't think I would want such a CLI to be distributed in this repository though. Someone else can make a different package that wraps this one in a CLI 👍

kentcdodds avatar Jul 01 '21 13:07 kentcdodds