Skip to content
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

feat!: mdc.config.js support, improve shiki bundle #129

Merged
merged 38 commits into from Feb 2, 2024
Merged

Conversation

antfu
Copy link
Member

@antfu antfu commented Jan 22, 2024

Resolves #124

Changes

  • Support mdc.config.ts/js file, imported via #mdc-configs
  • With highlighter: 'custom', it allows users to provide a highlighter function (instead of filepath) to have custom highlight. In that case, Shiki won't be included in the bundle at all.
  • Now the shiki instance is constructed with fine-grain bundle at build time; This allows MDC to only ships used languages/themes to the bundle, not all of them, making it works more efficient on edge. Accordingly, all languages need to be specified via highlighter.langs statically (it's a breaking change). highlighter.preload is deprecated.
    • The .output dist of the /playground comparison:
      • main branch: 22MB (4.5MB zipped)
      • this PR: 13MB (3.3Mb zipped)

Refactor

  • Move templates to /templates folder.
  • Refactored how highlighter is resolved.

TODOs

  • Hooks to add config sources
  • Passing code frame meta string to the pipeline
  • Test compatibility with downstream Nuxt Content and ecosystem

@antfu antfu marked this pull request as ready for review January 25, 2024 11:47
@antfu antfu changed the title feat!: wip mdc.config.js support feat!: mdc.config.js support, improve shiki bundle Jan 25, 2024
@antfu
Copy link
Member Author

antfu commented Jan 25, 2024

This PR is ready to review. Also did a test on nuxt.com with: nuxt/nuxt.com#1486

@antfu antfu requested a review from farnabaz January 25, 2024 11:53
@antfu antfu requested review from Atinux and farnabaz and removed request for farnabaz January 25, 2024 11:53
@antfu antfu mentioned this pull request Jan 25, 2024
2 tasks
@farnabaz
Copy link
Collaborator

farnabaz commented Jan 25, 2024

From what I understand now, we switched to use WASM by default. This breaks module's usability in some use-cases.

We need to consider a couple of usages:

  • MDC module should be able to parse & render contents in browser, with or without API
  • MDC module could be used in non-Nuxt context, like Strapi API. We should propose a solution for those environments.
    • Importing getMdcConfigs from #mdc-configs will fail outside of Nuxt.
    • We need a way to pass mdcConfig into the parser function in this case

@antfu
Copy link
Member Author

antfu commented Jan 25, 2024

For WASM, Shiki/Shikiji always needs WASM, and the do works in the browser. This PR does not change that.

MDC in non-Nuxt context

Can you give a more concrete example of what the usages be like? I am happy to expose the necessary options to make them decoupled.

Copy link
Collaborator

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@farnabaz farnabaz merged commit e158424 into main Feb 2, 2024
2 checks passed
@antfu antfu deleted the feat/mdc-configs branch February 2, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Support mdc.config.ts file
2 participants