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 { cn } from '@/lib/utils'
withDefaults(defineProps<{
const props = withDefaults(defineProps<{
name: string
align?: 'center' | 'start' | 'end'
sfcTsCode?: string
@ -40,7 +40,7 @@ const { style } = useConfigStore()
<TabsContent value="preview" class="relative rounded-md border">
<div class="flex items-center justify-between p-4">
<StyleSwitcher />
<Stackblitz :key="style" :style="style" :name="name" />
<Stackblitz :key="style" :style="style" :name="name" :code="decodeURIComponent(sfcTsCode ?? '')" />
</div>
<div
: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<{
name: string
code: string
style: Style
}>()
const sources = ref<Record<string, string>>({})
onMounted(() => {
const importName = `../../../src/lib/registry/${props.style}/example/${props.name}.vue?raw`
import(/* @vite-ignore */importName).then(
res => (sources.value['App.vue'] = res.default),
)
sources.value['App.vue'] = props.code
})
function handleClick() {