question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@mdx-js/mdx: compact output for recmaStringify

See original GitHub issue

Initial checklist

Problem

Out of the box, astring generates code with proper indentation and line breaks. This seems unnecessary for MDX specifically, as the output of the compiler does not need to be human readable in most cases.

Solution

It looks like we might be able to support a more compact output using a few astring.generate options, specifically indent and lineEnd (ref).

Looking at the internal recma-stringify plugin:

    const result = generate(tree, {
      generator,
+     indent: '',
+     lineEnd: ' ',
      comments: true,
      sourceMap
    })

This would result in a more compact output from MDX. We could also put this behind a flag (compact?) if we don’t want it to be default. I’d be happy to open a PR for this if we’re open to it!

(I’m not sure if this would result in broken output, it might require further testing)

Alternatives

Consumers can try to strip out some of this after the fact, but doing it during the stringify step seems the most reliable.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wooormcommented, Feb 17, 2022

If minification or smaller output is of concern: issues & PRs to continue discussing this are welcome!

1reaction
BRKalowcommented, Feb 17, 2022

Makes sense, thanks for the insight! I’ll close this out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@mdx-js/mdx - npm
Start using @mdx-js/mdx in your project by running `npm i @mdx-js/mdx`. There are 849 other projects in the npm registry using @mdx-js/mdx.
Read more >
How to compile MDX string to JS function, rather than ... - GitHub
The documentation seems aimed at .mdx files which are imported and thus compiled to modules, but I need a component function. My MDX...
Read more >
How To Use MDX Stored In Sanity In A Next.js Website
Use the default project output path (the current directory). Choose “clean project” from the template options. Install The Markdown Plugin For ...
Read more >
astrojs/mdx - Astro Documentation
These are plugins that modify the output estree directly. This is useful for modifying or injecting JavaScript variables in your MDX files. We...
Read more >
gatsby-plugin-mdx
gatsby-plugin-mdx is the official integration for using MDX with Gatsby. ... npm install gatsby-plugin-mdx gatsby-source-filesystem @mdx-js/react ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found