Skip to content

Commit 9707085

Browse files
committed
refactor: export VuePreview only one sfc
1 parent b5d1acc commit 9707085

File tree

9 files changed

+12
-37
lines changed

9 files changed

+12
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export default defineConfig({
3939

4040
// .vitepress/theme/index.ts
4141
import DefaultTheme from 'vitepress/theme'
42-
import { VuePreviewWrapper } from 'vite-plugin-vue-preview'
42+
import { VuePreview } from 'vite-plugin-vue-preview'
4343
import 'vite-plugin-vue-preview/dist/style.css'
4444

4545
export default {
4646
...DefaultTheme,
4747
enhanceApp(ctx) {
4848
DefaultTheme.enhanceApp(ctx)
49-
ctx.app.component('VuePreviewWrapper', VuePreviewWrapper)
49+
ctx.app.component('VuePreview', VuePreview)
5050
},
5151
}
5252
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
<VuePreview :store="store"></VuePreview>
2+
<Repl :store="store"></Repl>
33
</template>
44

55
<script lang="ts" setup>
6-
import { ReplStore, VuePreview } from './vue-repl'
6+
import { ReplStore, Repl } from './vue-repl'
77
import { provide, watch } from 'vue'
88
99
export interface Props {

src/components/vue-repl/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export { default as VuePreview } from './VuePreview.vue'
1+
export { default as Repl } from './Repl.vue'
22
export { default as Preview } from './output/Preview.vue'
33
export { ReplStore, File } from './store'
44
export { compileFile } from './transform'
5-
export type { Props as ReplProps } from './VuePreview.vue'
5+
export type { Props as ReplProps } from './Repl.vue'
66
export type { Store, StoreOptions, SFCOptions, StoreState } from './store'

src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
import VuePreviewWrapper from './components/VuePreviewWrapper.vue'
2-
export * from './components/vue-repl'
3-
4-
export {
5-
VuePreviewWrapper,
6-
}
1+
export { default as VuePreview } from './components/VuePreview.vue'

src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const end = '```'
44
const getCode = (code: string) => {
55
code = code.replace(start, '')
66
code = code.replace(end, '')
7-
return ` <VuePreviewWrapper code="${code}"></VuePreviewWrapper>\n`
7+
return ` <VuePreview code="${code}"></VuePreview>\n`
88
}
99

1010
export default function VuePreviewPlugin() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import DefaultTheme from 'vitepress/theme'
2-
import { VuePreviewWrapper } from '../../../../dist'
2+
import { VuePreview } from '../../../../dist'
33
import '../../../../dist/style.css'
44

55
export default {
66
...DefaultTheme,
77
enhanceApp(ctx) {
88
DefaultTheme.enhanceApp(ctx)
9-
ctx.app.component('VuePreviewWrapper', VuePreviewWrapper)
9+
ctx.app.component('VuePreview', VuePreview)
1010
},
1111
}

test/vitepress/index.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,4 @@
22

33
```vue preview
44
<template>Test Vitepress</template>
5-
```
6-
7-
<hr />
8-
9-
10-
```vue preview
11-
<template>Test Vitepress2</template>
125
```

test/vue/src/DemoSfc.vue

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22
import { provide } from 'vue'
33
44
import '../../../dist/style.css'
5-
import { VuePreview, ReplStore, VuePreviewWrapper } from '../../../dist'
6-
7-
const store = new ReplStore({ code: '<template><div>TEST</div></template>' });
8-
9-
provide('store', store)
10-
provide('clear-console', true)
5+
import { VuePreview } from '../../../dist'
116
127
const code = '<template><div>TEST VuePreviewWrapper</div></template>'
138
</script>
149

1510
<template>
1611
<div class="demo-sfc">
1712
<div class="demo-sfc__item">
18-
<VuePreview :store="store" ssr></VuePreview>
19-
</div>
20-
<div class="demo-sfc__item">
21-
<VuePreviewWrapper :code="code"></VuePreviewWrapper>
13+
<VuePreview :code="code"></VuePreview>
2214
</div>
2315
</div>
2416
</template>
@@ -29,11 +21,6 @@ const code = '<template><div>TEST VuePreviewWrapper</div></template>'
2921
padding-top: 100px;
3022
width: 1000px;
3123
display: flex;
32-
gap: 100px;
3324
justify-content: center;
34-
35-
&__item {
36-
width: 400px;
37-
}
3825
}
3926
</style>

0 commit comments

Comments
 (0)