-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathindex.ts
24 lines (22 loc) · 866 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { createVueToMarkdownRenderFn } from './vueToMarkdown';
import type { MarkdownOptions } from '../md/markdown/markdown';
import type { Plugin } from 'vite';
import { createMarkdownToVueRenderFn } from '../md/markdownToVue';
interface Options {
root?: string;
markdown?: MarkdownOptions;
}
export default (options: Options = {}): Plugin => {
const { root, markdown } = options;
const vueToMarkdown = createVueToMarkdownRenderFn(root);
const markdownToVue = createMarkdownToVueRenderFn(root, markdown);
return {
name: 'vueToMdToVue',
transform(code, id) {
if (id.endsWith('.vue') && id.indexOf('/demo/') > -1 && id.indexOf('index.vue') === -1) {
// transform .md files into vueSrc so plugin-vue can handle it
return { code: markdownToVue(vueToMarkdown(code, id).vueSrc, id).vueSrc, map: null };
}
},
};
};