Skip to content

Commit 02f1cfd

Browse files
committed
feat: unplugin
1 parent e96b78d commit 02f1cfd

38 files changed

+6487
-355
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ignore-workspace-root-check=true
22
strict-peer-dependencies=false
3+
shamefully-hoist=true

README.md

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,75 @@
1-
# vite-plugin-vue-markdown
1+
# unplugin-vue-markdown
22

3-
[![NPM version](https://img.shields.io/npm/v/vite-plugin-vue-markdown?color=a1b858)](https://www.npmjs.com/package/vite-plugin-vue-markdown)
3+
[![NPM version](https://img.shields.io/npm/v/unplugin-vue-markdown?color=a1b858)](https://www.npmjs.com/package/unplugin-vue-markdown)
44

5-
Compile Markdown to Vue component. A lite version of [vite-plugin-md](https://github.com/antfu/vite-plugin-md).
5+
Compile Markdown to Vue component.
66

77
- Use Markdown as Vue components
88
- Use Vue components in Markdown
99

1010
## Install
1111

12-
Install
13-
1412
```bash
15-
npm i vite-plugin-vue-markdown -D # yarn add vite-plugin-vue-markdown -D
13+
npm i unplugin-vue-markdown
1614
```
1715

18-
Add it to `vite.config.js`
16+
<details>
17+
<summary>Vite</summary><br>
1918

2019
```ts
21-
// vite.config.js
20+
// vite.config.ts
2221
import Vue from '@vitejs/plugin-vue'
23-
import Markdown from 'vite-plugin-vue-markdown'
22+
import Markdown from 'unplugin-vue-markdown/vite'
2423

25-
export default {
24+
export default defineConfig({
2625
plugins: [
2726
Vue({
28-
include: [/\.vue$/, /\.md$/], // <--
27+
include: [/\.vue$/, /\.md$/], // <-- allows Vue to compile Markdown files
2928
}),
30-
Markdown()
29+
Markdown({ /* options */ }),
3130
],
31+
})
32+
```
33+
34+
Example: [`examples/vite/`](./examples/vite/)
35+
36+
<br></details>
37+
38+
<details>
39+
<summary>Webpack</summary><br>
40+
41+
```ts
42+
// webpack.config.js
43+
module.exports = {
44+
/* ... */
45+
plugins: [
46+
require('unplugin-vue-markdown/webpack')({ /* options */ })
47+
]
3248
}
3349
```
3450

35-
And import it as a normal Vue component
51+
<br></details>
52+
53+
<details>
54+
<summary>Vue CLI</summary><br>
55+
56+
```ts
57+
// vue.config.js
58+
module.exports = {
59+
configureWebpack: {
60+
plugins: [
61+
require('unplugin-vue-markdown/webpack')({ /* options */ }),
62+
],
63+
},
64+
chainWebpack: (config) => {
65+
config.module
66+
.rule('vue')
67+
.test(/\.(vue|md)$/) // <-- allows Vue to compile Markdown files
68+
},
69+
}
70+
```
71+
72+
<br></details>
3673

3774
## Import Markdown as Vue components
3875

@@ -123,7 +160,7 @@ npm i @unhead/vue
123160
```js
124161
// vite.config.js
125162
import Vue from '@vitejs/plugin-vue'
126-
import Markdown from 'vite-plugin-vue-markdown'
163+
import Markdown from 'unplugin-vue-markdown'
127164

128165
export default {
129166
plugins: [
@@ -164,11 +201,11 @@ For more options available, please refer to [`@unhead/vue`'s docs](https://unhea
164201

165202
## Options
166203

167-
`vite-plugin-vue-markdown` uses [`markdown-it`](https://github.com/markdown-it/markdown-it) under the hood, see [`markdown-it`'s docs](https://markdown-it.github.io/markdown-it/) for more details
204+
`unplugin-vue-markdown` uses [`markdown-it`](https://github.com/markdown-it/markdown-it) under the hood, see [`markdown-it`'s docs](https://markdown-it.github.io/markdown-it/) for more details
168205

169206
```ts
170207
// vite.config.js
171-
import Markdown from 'vite-plugin-vue-markdown'
208+
import Markdown from 'unplugin-vue-markdown/vite'
172209
import MarkdownItAnchor from 'markdown-it-anchor'
173210
import MarkdownItPrism from 'markdown-it-prism'
174211

@@ -201,19 +238,23 @@ See [the tsdoc](./src/types.ts) for more advanced options
201238

202239
See the [/example](./example).
203240

204-
Or the pre-configured starter template [Vitesse](https://github.com/antfu/vitesse).
241+
Or the pre-configured Markdown template [Vitesse](https://github.com/antfu/vitesse).
205242

206243
## Integrations
207244

208-
### Work with [vite-plugin-voie](https://github.com/vamplate/vite-plugin-voie)
245+
### Work with [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages)
209246

210247
```ts
211-
import Markdown from 'vite-plugin-vue-markdown'
212-
import Voie from 'vite-plugin-voie'
248+
import Vue from '@vitejs/plugin-vue'
249+
import Markdown from 'unplugin-vue-markdown/vite'
250+
import Pages from 'vite-plugin-pages'
213251

214252
export default {
215253
plugins: [
216-
Voie({
254+
Vue({
255+
include: [/\.vue$/, /\.md$/],
256+
}),
257+
Pages({
217258
extensions: ['vue', 'md'],
218259
}),
219260
Markdown()
@@ -223,20 +264,23 @@ export default {
223264

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

267+
### Work with [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)
226268

227-
### Work with [vite-plugin-components](https://github.com/antfu/vite-plugin-components)
228-
229-
`vite-plugin-components` allows you to do on-demand components auto importing without worrying about registration.
269+
`vite-plugin-components` allows you to do on-demand components auto-importing without worrying about registration.
230270

231271
```ts
232-
import Markdown from 'vite-plugin-vue-markdown'
233-
import ViteComponents from 'vite-plugin-components'
272+
import Vue from '@vitejs/plugin-vue'
273+
import Markdown from 'unplugin-vue-markdown/vite'
274+
import Components from 'unplugin-vue-components/vite'
234275

235276
export default {
236277
plugins: [
278+
Vue({
279+
include: [/\.vue$/, /\.md$/],
280+
}),
237281
Markdown(),
238282
// should be placed after `Markdown()`
239-
ViteComponents({
283+
Components({
240284
// allow auto load markdown components under `./src/components/`
241285
extensions: ['vue', 'md'],
242286

example/App.vue renamed to examples/vite/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang='ts'>
22
import { ref } from 'vue'
3-
import ComponentA from '../README.md'
3+
import ComponentA from './README.md'
44
55
const current = ref()
66
</script>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)