All Projects → antfu → vite-plugin-md

antfu / vite-plugin-md

Licence: MIT License
Markdown with Vue for Vite

Programming Languages

typescript
32286 projects
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vite-plugin-md

vite-plugin-restart
Custom files/globs to restart Vite server
Stars: ✭ 92 (-68.17%)
Mutual labels:  vite, vite-plugin
vite-plugin-ssr
Like Next.js / Nuxt but as do-one-thing-do-it-well Vite plugin.
Stars: ✭ 1,703 (+489.27%)
Mutual labels:  vite, vite-plugin
vite-plugin-dts
A vite plugin for generating `.d.ts` files.
Stars: ✭ 539 (+86.51%)
Mutual labels:  vite, vite-plugin
vite-plugin-checker
💬 Vite plugin that provide checks of TypeScript, ESLint, vue-tsc, and more.
Stars: ✭ 338 (+16.96%)
Mutual labels:  vite, vite-plugin
vite-plugin-environment
Easily expose environment variables in Vite.js
Stars: ✭ 57 (-80.28%)
Mutual labels:  vite, vite-plugin
vite-plugin-html-template
html template for vite, like html-webpack-plugin for webpack.
Stars: ✭ 97 (-66.44%)
Mutual labels:  vite, vite-plugin
vite-plugins
🌱 为社区尽一份绵薄之力
Stars: ✭ 63 (-78.2%)
Mutual labels:  vite, vite-plugin
vite-plugin-env-compatible
Environment Variables Compatible for vite(with vue-cli, create-react-app and so on)
Stars: ✭ 35 (-87.89%)
Mutual labels:  vite, vite-plugin
vite-plugin-sleep
a vite plugin you never need. slow devServer and slow HMR.
Stars: ✭ 77 (-73.36%)
Mutual labels:  vite, vite-plugin
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (-76.12%)
Mutual labels:  vite, vite-plugin
vite-plugin-radar
All in one analytics loader for vite
Stars: ✭ 64 (-77.85%)
Mutual labels:  vite, vite-plugin
vite-plugin-inspect
Inspect the intermediate state of Vite plugins
Stars: ✭ 491 (+69.9%)
Mutual labels:  vite, vite-plugin
vite-plugin-banner
A banner plugin for Vite. It can adds a banner to the top of each generated chunk.
Stars: ✭ 39 (-86.51%)
Mutual labels:  vite, vite-plugin
vite-plugin-compress
Compress your bundle + assets from Vite
Stars: ✭ 103 (-64.36%)
Mutual labels:  vite, vite-plugin
vite-plugin-relay
A vite plugin for Relay
Stars: ✭ 44 (-84.78%)
Mutual labels:  vite, vite-plugin
vite-plugin-sloth
Fresh take on static site generation, using HTML-first approach to build website. Powered by ⚡️ Vite
Stars: ✭ 39 (-86.51%)
Mutual labels:  vite
twoslash
You take some Shiki, add a hint of TypeScript compiler, and 🎉 incredible static code samples
Stars: ✭ 596 (+106.23%)
Mutual labels:  markdown-it
vite-ts-tailwind-starter
Opinionated Vite + Vue 3 + TypeScript + Tailwind CSS starter template w/ tests and CI.
Stars: ✭ 228 (-21.11%)
Mutual labels:  vite
vue3-demo
💡 vue3新特性示例: 响应式API、组合式API、TodoMVC
Stars: ✭ 114 (-60.55%)
Mutual labels:  vite
remastered
A full-stack approach to React development
Stars: ✭ 50 (-82.7%)
Mutual labels:  vite

vite-plugin-md

Markdown for Vite

  • Use Markdown as Vue components
  • Use Vue components in Markdown

NPM version

ℹ️ 0.2.x is for Vite 2 and 0.1.x is for Vite 1

Install

Install

npm i vite-plugin-md -D # yarn add vite-plugin-md -D

Add it to vite.config.js

// vite.config.js
import Vue from '@vitejs/plugin-vue'
import Markdown from 'vite-plugin-md'

export default {
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    Markdown()
  ],
}

And import it as a normal Vue component

Import Markdown as Vue components

<template>
  <HelloWorld />
</template>

<script>
import HelloWorld from './README.md'

export default {
  components: {
    HelloWorld,
  },
}
</script>

Use Vue Components inside Markdown

You can even use Vue components inside your markdown, for example

<Counter :init='5'/>

Note you can either register the components globally, or use the <script setup> tag to register them locally.

import { createApp } from 'vue'
import App from './App.vue'
import Counter from './Counter.vue'

const app = createApp(App)

// register global
app.component('Counter', Counter) // <--

app.mount()
<script setup>
import { Counter } from './Counter.vue
</script>

<Counter :init='5'/>

Or you can use vite-plugin-components for auto components registration.

Frontmatter

Frontmatter will be parsed and inject into Vue's instance data frontmatter field.

For example:

---
name: My Cool App
---

# Hello World

This is {{frontmatter.name}}

Will be rendered as

<h1>Hello World</h1>
<p>This is My Cool App</p>

It will also be passed to the wrapper component's props if you have set wrapperComponent option.

Document head and meta

To manage document head and meta, you would need to install @vueuse/head and do some setup.

npm i @vueuse/head
// vite.config.js
import Vue from '@vitejs/plugin-vue'
import Markdown from 'vite-plugin-md'

export default {
  plugins: [
    Vue({
      include: [/\.vue$/, /\.md$/],
    }),
    Markdown({
      headEnabled: true // <--
    })
  ]
}
// src/main.js
import { createApp } from 'vue'
import { createHead } from '@vueuse/head' // <--

const app = createApp(App)

const head = createHead() // <--
app.use(head) // <--

Then you can use frontmatter to control the head. For example:

---
title: My Cool App
meta:
  - name: description
    content: Hello World
---

For more options available, please refer to @vueuse/head's docs.

Options

vite-plugin-md uses markdown-it under the hood, see markdown-it's docs for more details

// vite.config.js
import Markdown from 'vite-plugin-md'

export default {
  plugins: [
    Markdown({
      // default options passed to markdown-it
      // see: https://markdown-it.github.io/markdown-it/
      markdownItOptions: {
        html: true,
        linkify: true,
        typographer: true,
      },
      // A function providing the Markdown It instance gets the ability to apply custom settings/plugins
      markdownItSetup(md) {
        // for example
        md.use(require('markdown-it-anchor'))
        md.use(require('markdown-it-prism'))
      },
      // Class names for the wrapper div
      wrapperClasses: 'markdown-body'
    })
  ],
}

See the tsdoc for more advanced options

Example

See the /example.

Or the pre-configured starter template Vitesse.

Integrations

Work with vite-plugin-voie

import Markdown from 'vite-plugin-md'
import Voie from 'vite-plugin-voie'

export default {
  plugins: [
    Voie({
      extensions: ['vue', 'md'],
    }),
    Markdown()
  ],
}

Put your markdown under ./src/pages/xx.md, then you can access the page via route /xx.

Work with vite-plugin-components

vite-plugin-components allows you to do on-demand components auto importing without worrying about registration.

import Markdown from 'vite-plugin-md'
import ViteComponents from 'vite-plugin-components'

export default {
  plugins: [
    Markdown(),
    // should be placed after `Markdown()`
    ViteComponents({
      // allow auto load markdown components under `./src/components/`
      extensions: ['vue', 'md'],

      // allow auto import and register components used in markdown
      customLoaderMatcher: path => path.endsWith('.md'),
    })
  ],
}

Components under ./src/components can be directly used in markdown components, and markdown components can also be put under ./src/components to be auto imported.

TypeScript Shim

declare module '*.vue' {
  import { ComponentOptions } from 'vue'
  const Component: ComponentOptions
  export default Component
}

declare module '*.md' {
  import { ComponentOptions } from 'vue'
  const Component: ComponentOptions
  export default Component
}

License

MIT License © 2020-PRESENT Anthony Fu

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].