Skip to content

Commit 03665a4

Browse files
authored
feat!: migrate to unplugin (#24)
1 parent e96b78d commit 03665a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6539
-363
lines changed

.npmrc

+1
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

+95-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,97 @@
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

7-
- Use Markdown as Vue components
8-
- Use Vue components in Markdown
7+
- 📚 Use Markdown as Vue components
8+
- 💚 Use Vue components in Markdown
9+
- ⚡️ Supports Vite, Webpack, Vue CLI and more, powered by [unplugin](https://github.com/unjs/unplugin).
910

1011
## Install
1112

12-
Install
13-
1413
```bash
15-
npm i vite-plugin-vue-markdown -D # yarn add vite-plugin-vue-markdown -D
14+
npm i unplugin-vue-markdown
1615
```
1716

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

2020
```ts
21-
// vite.config.js
21+
// vite.config.ts
2222
import Vue from '@vitejs/plugin-vue'
23-
import Markdown from 'vite-plugin-vue-markdown'
23+
import Markdown from 'unplugin-vue-markdown/vite'
2424

25-
export default {
25+
export default defineConfig({
2626
plugins: [
2727
Vue({
28-
include: [/\.vue$/, /\.md$/], // <--
28+
include: [/\.vue$/, /\.md$/], // <-- allows Vue to compile Markdown files
2929
}),
30-
Markdown()
30+
Markdown({ /* options */ }),
3131
],
32+
})
33+
```
34+
35+
Example: [`examples/vite`](./examples/vite/)
36+
37+
<br></details>
38+
39+
<details>
40+
<summary>Webpack</summary><br>
41+
42+
```ts
43+
// webpack.config.js
44+
const { VueLoaderPlugin } = require('vue-loader')
45+
const Markdown = require('unplugin-vue-markdown/webpack')
46+
47+
module.exports = {
48+
/* ... */
49+
module: {
50+
rules: [
51+
// ... other rules
52+
{
53+
test: /\.(vue|md)$/,
54+
loader: 'vue-loader'
55+
}
56+
]
57+
},
58+
plugins: [
59+
new VueLoaderPlugin(),
60+
Markdown({ /* options */ })
61+
]
62+
}
63+
```
64+
65+
<br></details>
66+
67+
<details>
68+
<summary>Vue CLI</summary><br>
69+
70+
```ts
71+
// vue.config.js
72+
const Markdown = require('unplugin-vue-markdown/webpack')
73+
74+
module.exports = {
75+
parallel: false, // Disable thread-loader which will cause errors, we are still investigating the root cause
76+
chainWebpack: (config) => {
77+
config.module
78+
.rule('vue')
79+
.test(/\.(vue|md)$/) // <-- allows Vue to compile Markdown files
80+
81+
config
82+
.plugin('markdown')
83+
.use(Markdown({
84+
markdownItUses: [
85+
prism,
86+
],
87+
}))
88+
},
3289
}
3390
```
3491

35-
And import it as a normal Vue component
92+
Example: [`examples/vue-cli`](./examples/vue-cli/)
93+
94+
<br></details>
3695

3796
## Import Markdown as Vue components
3897

@@ -123,7 +182,7 @@ npm i @unhead/vue
123182
```js
124183
// vite.config.js
125184
import Vue from '@vitejs/plugin-vue'
126-
import Markdown from 'vite-plugin-vue-markdown'
185+
import Markdown from 'unplugin-vue-markdown/vite'
127186

128187
export default {
129188
plugins: [
@@ -164,11 +223,11 @@ For more options available, please refer to [`@unhead/vue`'s docs](https://unhea
164223

165224
## Options
166225

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
226+
`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
168227

169228
```ts
170229
// vite.config.js
171-
import Markdown from 'vite-plugin-vue-markdown'
230+
import Markdown from 'unplugin-vue-markdown/vite'
172231
import MarkdownItAnchor from 'markdown-it-anchor'
173232
import MarkdownItPrism from 'markdown-it-prism'
174233

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

202261
See the [/example](./example).
203262

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

206265
## Integrations
207266

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

210269
```ts
211-
import Markdown from 'vite-plugin-vue-markdown'
212-
import Voie from 'vite-plugin-voie'
270+
import Vue from '@vitejs/plugin-vue'
271+
import Markdown from 'unplugin-vue-markdown/vite'
272+
import Pages from 'vite-plugin-pages'
213273

214274
export default {
215275
plugins: [
216-
Voie({
276+
Vue({
277+
include: [/\.vue$/, /\.md$/],
278+
}),
279+
Pages({
217280
extensions: ['vue', 'md'],
218281
}),
219282
Markdown()
@@ -223,20 +286,23 @@ export default {
223286

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

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

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.
291+
`vite-plugin-components` allows you to do on-demand components auto-importing without worrying about registration.
230292

231293
```ts
232-
import Markdown from 'vite-plugin-vue-markdown'
233-
import ViteComponents from 'vite-plugin-components'
294+
import Vue from '@vitejs/plugin-vue'
295+
import Markdown from 'unplugin-vue-markdown/vite'
296+
import Components from 'unplugin-vue-components/vite'
234297

235298
export default {
236299
plugins: [
300+
Vue({
301+
include: [/\.vue$/, /\.md$/],
302+
}),
237303
Markdown(),
238304
// should be placed after `Markdown()`
239-
ViteComponents({
305+
Components({
240306
// allow auto load markdown components under `./src/components/`
241307
extensions: ['vue', 'md'],
242308

example/App.vue examples/vite/App.vue

+1-1
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)