fix: cant fetch ?raw dynamically after bundling

This commit is contained in:
zernonia 2023-10-21 20:41:34 +08:00
parent f6a2460b81
commit 511ce84942
2 changed files with 4 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/lib/registry/default
import { useConfigStore } from '@/stores/config' import { useConfigStore } from '@/stores/config'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
withDefaults(defineProps<{ const props = withDefaults(defineProps<{
name: string name: string
align?: 'center' | 'start' | 'end' align?: 'center' | 'start' | 'end'
sfcTsCode?: string sfcTsCode?: string
@ -40,7 +40,7 @@ const { style } = useConfigStore()
<TabsContent value="preview" class="relative rounded-md border"> <TabsContent value="preview" class="relative rounded-md border">
<div class="flex items-center justify-between p-4"> <div class="flex items-center justify-between p-4">
<StyleSwitcher /> <StyleSwitcher />
<Stackblitz :key="style" :style="style" :name="name" /> <Stackblitz :key="style" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
</div> </div>
<div <div
:class="cn('preview flex min-h-[350px] w-full justify-center p-6 lg:p-10', { :class="cn('preview flex min-h-[350px] w-full justify-center p-6 lg:p-10', {

View File

@ -7,16 +7,14 @@ import { type Style } from '@/lib/registry/styles'
const props = defineProps<{ const props = defineProps<{
name: string name: string
code: string
style: Style style: Style
}>() }>()
const sources = ref<Record<string, string>>({}) const sources = ref<Record<string, string>>({})
onMounted(() => { onMounted(() => {
const importName = `../../../src/lib/registry/${props.style}/example/${props.name}.vue?raw` sources.value['App.vue'] = props.code
import(/* @vite-ignore */importName).then(
res => (sources.value['App.vue'] = res.default),
)
}) })
function handleClick() { function handleClick() {