This repository was archived by the owner on Jan 9, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Expand file tree Collapse file tree 3 files changed +40
-12
lines changed Original file line number Diff line number Diff line change 8
8
<script lang="ts">
9
9
import { defineComponent , Component } from ' vue'
10
10
import { useAsyncState } from ' @vueuse/core'
11
+ import { imports } from ' @/imports'
11
12
12
13
export default defineComponent ({
13
14
name: ' VueFile' ,
@@ -21,8 +22,14 @@ export default defineComponent({
21
22
22
23
setup(props ) {
23
24
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
+ }
26
33
}, null )
27
34
28
35
return {
Original file line number Diff line number Diff line change 4
4
5
5
import { Ref } from 'vue'
6
6
import { useAsyncState } from '@vueuse/core'
7
+ import { imports } from '@/imports'
7
8
8
9
export interface IPen {
9
10
template : string
@@ -21,16 +22,21 @@ const parseTemplate = (target: string, template: string): string => {
21
22
22
23
export const usePen = ( file : string ) : Ref < IPen | null > => {
23
24
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
34
40
}
35
41
} , null )
36
42
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments