Getting Started

Vue + Vite

Add Boneprint to a Vue 3 app built with Vite.

Install

npm install boneprint

The package ships .vue files, so the app needs @vitejs/plugin-vue, which every Vue + Vite app already has. The styles come with the components: there's no CSS file to import.

Pick one of three ways to make the components available.

Import where you use it

The simplest way, nothing to set up:

<script setup lang="ts">
import { Skeleton } from 'boneprint'
</script>

Register globally

main.ts
import { createApp } from 'vue'
import { boneprint } from 'boneprint'
import App from './App.vue'

createApp(App).use(boneprint).mount('#app')

<Skeleton>, <SkeletonBox> and <SkeletonSuspense> then work in every template. The plugin also takes the options: .use(boneprint, { reveal: 'sequence' }). It's the only way to change the defaults for the whole app, so it works alongside the other two ways as well.

Auto-import

If the app auto-imports components, add the resolver. With unplugin-vue-components:

import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { boneprintResolver } from 'boneprint/resolver'

export default defineConfig({
  plugins: [
    vue(),
    Components({ resolvers: [boneprintResolver()] }),
    AutoImport({ imports: ['vue', { boneprint: ['forgetSkeletons', 'useInSkeleton'] }] }),
  ],
})

The generated components.d.ts keeps the slot's data typed, as with a direct import.

Loading the data

:of takes anything with data, status and error, so a TanStack Query result goes in as it is:

<script setup lang="ts">
const posts = useQuery({ queryKey: ['posts'], queryFn: fetchPosts })
const sample: Post[] = [{ id: 1, title: 'A title of about this length' }]
</script>

<template>
  <Skeleton :of="posts" :sample>
    <template #default="{ data }">
      <PostCard v-for="post in data" :key="post.id" :post />
    </template>
  </Skeleton>
</template>

With anything else, set the state by hand: :data, :loading, :empty and :error. See States.

Compared with Nuxt

Everything works the same, except one thing a single-page app doesn't need: without a server there's no HTML to draw a remembered shape into before JavaScript loads. The shape appears when the component mounts, which in a single-page app is the first moment anything is on screen at all.

The remembered shape is keyed by the page, read from vue-router when there is one, or from the address otherwise.