-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use mdx-loader instead of mdx.macro #589
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://mdx-git-fork-adueck-master.mdx.now.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this @adueck!
I'd lean toward keeping the Babel macro as the recommendation and example.
The React team wants to avoid custom loader syntax, as evidenced by eslint import/no-webpack-loader-syntax
being on by default.
While not having live reloading today is less than ideal, babel has a proposed solution babel/babel#8497 that will enable webpack, create react app, and others to handle this without workarounds.
I'd rather wait for the full solution than ask adopters to apply a work around that they'll want to rollback at a later date.
@ChristianMurphy Yes I see your point, fair enough. Just a couple of things to consider (if it affects your decision at all) The README for mdx-loader points out that
But I guess that still is custom loader syntax. I also think it's important to remember that mdx.macro does not work with v. 1 of mdx, and this probably will not change anytime soon, based on this comment from the author. Anyways ultimately your call of course 😄. I've chosen to use
Maybe it's best just to let people know that this |
That appears this is due to
🤔 the babel macro could be something worth considering moving into core, rather than a community plugin.
Definitely! letting folks know it's an option would be nice. |
Yeah, definitely. Would you be interested in adding
This would be a great guide! |
Sure, I'd be happy to transfer mdx.macro to the mdx-js monorepo. It'd make sense to be able to write inline MDX using a macro. It really needs a complete rewrite though, and that rewrite should probably limit it to inline MDX. It's not worth the effort to make it handle external files, as loading external files with babel-plugin-macros is just not a good idea. Even if babel/babel#8497 is eventually implemented, it would still require each macro to handle all the file loading edge cases by itself. Why bother when Webpack was actually built for this, and does a perfectly good job already? I mean, compare these two hypothetical syntaxes: // babel-macros
import mdx from 'mdx.macro'
let Doc = React.lazy(() => mdx.import('./doc.mdx'))
// webpack loaders
let Doc = React.lazy(() => import('!mdx-loader!./doc.mdx')) Neither of these are plain JavaScript -- they both require a build step. Sure, one is allowed by the CRA linter, but the other actually works. There's nothing objectively better about the macros syntax, other than the fact that some lint rules have been put in place that make the other one uglier. And if we're going to be fair, the loader syntax is actually far nicer when you have an MDX loader set up in the Webpack config. So I guess what I'm saying is I'd be more than happy to transfer mdx.macro. It makes a lot of sense to have an option to write inline mdx using macros. However, for importing mdx files, we really should recommend that people use a Webpack loader -- regardless of what the CRA team says. |
@jamesknelson So by a Webpack loader you mean It seems that a lot of, if not most use cases would be importing |
@adueck There's also @mdx-js/loader, which is the official loader and seems to get much more use than mdx-loader. |
@jamesknelson But from my understaing @mdx-js/loader doesn't have id slugs on headings, table of contents, front matter parsing etc. included in there that all has to be added by the user, am I right? If so all that stuff is what makes your mdx-loader such a great go-to. 👍 |
@adueck Are there any special instructions for how to use this with const mdxContext = require.context('!babel-loader!mdx-loader!../../../../packages', true, /(\w+)\.(\w+)\.(mdx?)/); And I'm getting a whole bunch of "Unexpected token" errors from |
@Lillebo Sorry, I haven't used it with
|
@adueck looks like a merge conflict has cropped up, any chance this could be rebased and updated to use |
@adueck Friendly ping! 🛎😊 |
mdx.macro has become totally detached from currently documented mdx functionality. Please merge this PR so users don't find out the hard way that the documentation is recommending an unmaintained and outdated pre-1.0 installation. |
@thediveo As this PR seems stalled, a new PR would be appreciated! |
Don't see how a fresh PR will get better treatment than the original one? The project maintainers let this PR decomposing already for, wait, 2 years if I'm not mistaken. I can supply a PR, but only if the maintainers signal "go on". I noticed that I didn't need to create any babel-related resource file, for a current cra it seems to work out-of-the-box. |
I'm a maintainer and I'm "signalling" that. |
Create React App is the most looked at resource by users here on GitHub. But it’s suggesting an old, unmaintained, and buggy way to use MDX. This instead updates the guide to use our maintained projects, without having to eject from CRA. As CRA itself is an ever-changing “init” tool, which can support MDX by following a couple steps, I don’t think it’s wise to have an example in the project: we want folks to do `npx create-react-app ...`, not clone our custom example. Not having CRA checked in also makes for a faster `yarn install`. Perhaps developing our own [CRA template](https://create-react-app.dev/docs/custom-templates) might be nice for the future, but for now I’ve kept it at an up to date and working guide. Related to GH-1015. Related to GH-1388. Closes GH-365. Closes GH-589.
Create React App is the most looked at resource by users here on GitHub. But it’s suggesting an old, unmaintained, and buggy way to use MDX. This instead updates the guide to use our maintained projects, without having to eject from CRA. As CRA itself is an ever-changing “init” tool, which can support MDX by following a couple steps, I don’t think it’s wise to have an example in the project: we want folks to do `npx create-react-app ...`, not clone our custom example. Not having CRA checked in also makes for a faster `yarn install`. Perhaps developing our own [CRA template](https://create-react-app.dev/docs/custom-templates) might be nice for the future, but for now I’ve kept it at an up to date and working guide. Related to GH-1015. Related to GH-1388. Closes GH-365. Closes GH-589.
Create React App is the most looked at resource by users here on GitHub. But it’s suggesting an old, unmaintained, and buggy way to use MDX. This instead updates the guide to use our maintained projects, without having to eject from CRA. As CRA itself is an ever-changing “init” tool, which can support MDX by following a couple steps, I don’t think it’s wise to have an example in the project: we want folks to do `npx create-react-app ...`, not clone our custom example. Not having CRA checked in also makes for a faster `yarn install`. Perhaps developing our own [CRA template](https://create-react-app.dev/docs/custom-templates) might be nice for the future, but for now I’ve kept it at an up to date and working guide. Related to GH-1015. Related to GH-1388. Closes GH-365. Closes GH-589. Closes GH-1422. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
I think it would be better to suggest using
mdx-loader
withcreate-react-app
because:mdx-loader
supports v. 1 of@mdx-js/mdx
, so crucial things like JSX in the middle of markdown copmonents works. (See this recently closed issue.).mdx.macro
does not support the latest@mdx-js/mdx
I've updated both the docs page and the full example.