VOOZH about

URL: https://blog.logrocket.com/getting-started-with-mdx-and-vue-js-nuxt-js/

โ‡ฑ Getting started with MDX and Vue.js/Nuxt.js - LogRocket Blog


2020-10-14
1153
#js libraries#vue
Kelvin Omereshone
26942
๐Ÿ‘ Image

See how LogRocket's Galileo AI surfaces the most severe issues for you

No signup required

Check it out

Markdown, since its introduction to the web, has allowed content creators (such as technical writers and documentation engineers, etc.) to have a more simplistic tool to do their authoring in. In this article, we will have a look at MDX and how to get started with it in Nuxt.js applications.

๐Ÿ‘ Getting started with MDX and Vue.js/Nuxt.js

๐Ÿš€ Sign up for The Replay newsletter

The Replay is a weekly newsletter for dev and engineering leaders.

Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.

Prerequisites

  • To follow along youโ€™ll need to be familiar with Markdown and Vue.js/Nuxt.js

What is MDX?

MDX is a syntax extension that allows you to write JSX in your Markdown documents. Also, according to the official MDX documentation, MDX is:

An authorable format that lets you seamlessly write JSX in your Markdown documents. You can import components, such as interactive charts or alerts, and embed them within your content

So basically, MDX is Markdown with JSX. Before MDX, writing JSX in Markdown was a hassle because the simplicity of authoring Markdown was lost in the process of sprinkling JSX in it.

MDX opens the door to a lot of fun applications to Markdown documents. For example, the Chakra UI documentation website uses MDX to allow readers to edit components and see their changes live on the page.

MDX is useful for design systems documentations like we mentioned above with the Chakra UI documentation usage of MDX. MDX also allows you to import Markdown (.md or .mdx) files as components!

Features of MDX

  • MDX blends Markdown and JSX perfectly to allow for more expressive authoring in a JX-based project
  • Easily import and render JSX components in your markdown documents
  • Highly customizable which allows you to determine which component is rendered for each markdown element
  • The simplicity of markdown is maintained, you only need to use JSX where you want to
  • MDX does not have any runtime because all compilation occurs during the build stage. This make MDX really fast

MDX and Vue.js

Though JSX was originally used in React projects, you can now use it as well in Vue.js. With that said, you can freely integrate MDX in your Vue.js projects.

Features of MDX in Vue.js

  • MDX allows you to import .md or .mdx files as Vue components
  • MDX also allows you to import Vue components inside markdown documents
  • Using the MDX provider, you can replace markdown elements with Vue components

Letโ€™s see these features in action by integrating MDX and Vue. We will get started by creating a fresh Vue project. Using the Vue CLI run:

vue create mdx-vue-demo

After creating the Vue projects we will add MDX support by installing @mdx-js/vue-loader which is the official loader that makes it possible to use MDX in Vue. Letโ€™s install it below:

npm install @mdx-js/vue-loader

After weโ€™ve installed the loader we will then include the loader inside our projectโ€™s webpack config. Since we are using Vue CLI, we can create a vue.config.js file in the root of our projects, and on the configureWebpack property, we include @mdx-js/vue-loader under the module rules:

// vue.config.js
module.exports = {
 configureWebpack: {
 module: {
 rules: [
 {
 test: /\.mdx?$/,
 use: ['babel-loader', '@mdx-js/vue-loader'],
 },
 ],
 },
 },
};

What the code means is that any file ending with .md or .mdx will be handled by both babel-loader and @mdx-js/vue-loader

The step above is still the same if you are configuring your Vue application using webpack. You just have to include the loader in webpack.config.js likes so:

// webpack.config.js
module: {
 rules: [
 // ...
 {
 test: /\.mdx?$/,
 use: ['babel-loader', '@mdx-js/vue-loader']
 }
 ]
}

Importing Markdown in a Vue component

Now that we have both installed and configured @mdx-js/vue-loader letโ€™s create a md file in src/ directory and render it as a Vue component in src/App.vue. We will create MyFirstMdx.mdx in the components/ directory and add the following content:

# Hello LogRocket

from markdown powered by MDX

Import the .mdx file in src/App.vue as you will import a Vue component. Like so:

import MyFirstMDX from '@/components/MyFirstMdx.mdx'

We will register the component:

components: {
 MyFirstMdx
}

Then replace the template in App.vue with <my-first-mdx />. The App.vue file should now look like this:

<template>
 <div id="app">
 <my-first-mdx />
 </div>
</template>
<script>
import MyFirstMdx from "./components/MyFirstMdx.mdx";
export default {
 name: "App",
 components: {
 MyFirstMdx,
 },
};
</script>
<style>
#app {
 font-family: Avenir, Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
</style>

Start the Vue development server and you will see the content of MyFirstMdx.mdx when you visit your app in the browser.

Importing a Vue component in Markdown

To demonstrate how MDX makes it easy to import Vue components in markdown documents, we will create a component in components/ that allows users to clap for MDX(why not!). We will call this component ClapForMdx.vue. Add the following snippets to it:

// components/ClapForMdx.vue
<template>
 <section>
 <p class="claps">{{ claps }}</p>
 <button class="clap-btn" @click="clap" title="Clap for MDX">๐Ÿ‘</button>
 </section>
</template>
<script>
export default {
 data() {
 return {
 claps: 0,
 };
 },
 methods: {
 clap() {
 this.claps += 5;
 },
 },
};
</script>
<style>
.claps {
 font-size: 3rem;
 color: #f0ab1f;
}
.clap-btn {
 padding: 1rem;
 border-radius: 100%;
 font-size: 2.5rem;
 cursor: pointer;
 border: 1px solid #f0ab1f;
 box-shadow: -4px -1px 18px -10px rgba(0, 0, 0, 0.75);
}
.clap-btn:focus {
 outline: none;
}
</style>

Then modify MyFirstMdx.mdx to this

import ClapForMdx from './ClapForMdx.vue';
# Hello LogRocket
from markdown powered by MDX
<ClapForMdx />

And you should get this in your browser:

๐Ÿ‘ clap for mdx

You can interact with the button and it will respond as expected!

๐Ÿ‘ ui state at 200 claps

MDX and Nuxt.js

We have now seen how MDX works in a Vue project. In this final section, we will introduce the installation in a Nuxt.js application. Since Nuxt is a framework for Vue, our code examples will work in it so we wonโ€™t need to repeat that.

To get started we will need to add the official NuxtJS module for MDX in a Nuxt.js project as a development dependency. Run the following in your terminal:

npm install --save-dev @nuxtjs/mdx

Then in nuxt.config.js add the module to buildModule property like so:

buildModules: ['@nuxtjs/mdx']

If you are using nuxt < 2.9.0, use the modules property instead.

And thatโ€™s it! You can reuse our examples above and it will work.


Over 200k developers use LogRocket to create better digital experiences

๐Ÿ‘ Image
Learn more โ†’

Conclusion

In this component-driven era, MDX allows you to mix markdown and JSX seamlessly. In this article, we looked at how to set up and use MDX in your Vue.js/Nuxt.js projects. If you want to keep exploring MDX or its integration with Vue.js or Nuxt.js, check out these resources:

Here is the link to the GitHub repo for our demo VueJS project.

LogRocket understands everything users do in your Vue apps.

Debugging Vue.js applications can be difficult, especially when users experience issues that are difficult to reproduce. If youโ€™re interested in monitoring and tracking Vue mutations and actions for all of your users in production, try LogRocket.

๐Ÿ‘ LogRocket Dashboard Free Trial Banner

LogRocket lets you replay user sessions, eliminating guesswork by showing exactly what users experienced. It captures console logs, errors, network requests, and pixel-perfect DOM recordings โ€” compatible with all frameworks.

With Galileo AI, you can instantly identify and explain user struggles with automated monitoring of your entire product experience.

Modernize how you debug your Vue apps โ€” start monitoring for free.

Are you adding new JS libraries to build new features or improve performance? What if theyโ€™re doing the opposite?

Thereโ€™s no doubt that frontends are getting more complex. As you add new JavaScript libraries and other dependencies to your app, youโ€™ll need more visibility to ensure your users donโ€™t run into unknown issues.

LogRocket is a frontend application monitoring solution that lets you replay JavaScript errors as if they happened in your own browser so you can react to bugs more effectively.

๐Ÿ‘ LogRocket Dashboard Free Trial Banner

LogRocket works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your appโ€™s performance, reporting metrics like client CPU load, client memory usage, and more.

Build confidently โ€” start monitoring for free.

๐Ÿ‘ Image
๐Ÿ‘ Image
๐Ÿ‘ Image

Stop guessing about your digital experience with LogRocket

Get started for free

Recent posts:

How to build a virtual engineering team with Gemini CLI subagents

Learn how to use Gemini CLI subagents to delegate frontend, backend, testing, and docs tasks to specialized agents with guardrails and clear ownership.

๐Ÿ‘ Image
Emmanuel John
Jun 18, 2026 โ‹… 10 min read

Debug Next.js apps with AI agents and next-browser

Learn how next-browser gives AI agents runtime context for debugging Next.js apps, including React props, hydration, PPR, forms, and performance.

๐Ÿ‘ Image
Emmanuel John
Jun 17, 2026 โ‹… 9 min read

Stop hardcoding LLM SDKs: Dynamic LLM routing with OpenRouter and Next.js

Build dynamic LLM routing in Next.js with OpenRouter, TanStack AI, task classification, model fallbacks, and cost-aware routing.

๐Ÿ‘ Image
Chizaram Ken
Jun 16, 2026 โ‹… 13 min read

What is TSRX?: What JSX would look like if it were designed today

TSRX adds first-class control flow, conditional hooks, and scoped styles to React via a TypeScript compiler extension โ€” no new framework required.

๐Ÿ‘ Image
Ikeh Akinyemi
Jun 12, 2026 โ‹… 6 min read
View all posts

Would you be interested in joining LogRocket's developer community?

Join LogRocketโ€™s Content Advisory Board. Youโ€™ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now