Skip to content
This repository was archived by the owner on Jan 9, 2022. It is now read-only.

Commit e1569d5

Browse files
committed
fix(docs): make explicit import of example components
1 parent 07daac0 commit e1569d5

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

docs/src/components/Components/VueFile.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script lang="ts">
99
import { defineComponent, Component } from 'vue'
1010
import { useAsyncState } from '@vueuse/core'
11+
import { imports } from '@/imports'
1112
1213
export default defineComponent({
1314
name: 'VueFile',
@@ -21,8 +22,14 @@ export default defineComponent({
2122
2223
setup(props) {
2324
const { state: component } = useAsyncState(async () => {
24-
const res = await import(`../Examples/${props.file}.vue`)
25-
return res.default as Component
25+
try {
26+
const { component } = (await imports[props.file]()) as { component: Component }
27+
28+
return component
29+
} catch (error) {
30+
console.warn(`Example component "${props.file}" not found`)
31+
return null
32+
}
2633
}, null)
2734
2835
return {

docs/src/composable/pen.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { Ref } from 'vue'
66
import { useAsyncState } from '@vueuse/core'
7+
import { imports } from '@/imports'
78

89
export interface IPen {
910
template: string
@@ -21,16 +22,21 @@ const parseTemplate = (target: string, template: string): string => {
2122

2223
export const usePen = (file: string): Ref<IPen | null> => {
2324
const { state } = useAsyncState(async () => {
24-
const { default: res } = await import(`../components/Examples/${file}.vue?raw`)
25-
26-
const template = parseTemplate('template', res)
27-
const script = parseTemplate('script', res)
28-
const style = parseTemplate('style', res)
29-
30-
return {
31-
template,
32-
script,
33-
style,
25+
try {
26+
const { raw } = (await imports[file]()) as { raw: string }
27+
28+
const template = parseTemplate('template', raw)
29+
const script = parseTemplate('script', raw)
30+
const style = parseTemplate('style', raw)
31+
32+
return {
33+
template,
34+
script,
35+
style,
36+
}
37+
} catch (error) {
38+
console.warn(`Example component "${file}" not found`)
39+
return null
3440
}
3541
}, null)
3642

docs/src/imports.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const imports = {
2+
async 'Introduction/GettingStartedExample'() {
3+
return {
4+
component: (await import('./components/Examples/Introduction/GettingStartedExample.vue')).default,
5+
raw: (await import('./components/Examples/Introduction/GettingStartedExample.vue?raw')).default,
6+
}
7+
},
8+
9+
async 'Introduction/GettingStartedExampleStyled'() {
10+
return {
11+
component: (await import('./components/Examples/Introduction/GettingStartedExampleStyled.vue')).default,
12+
raw: (await import('./components/Examples/Introduction/GettingStartedExampleStyled.vue?raw')).default,
13+
}
14+
},
15+
} as any

0 commit comments

Comments
 (0)