---
title: "Vue + Vite"
description: "Add Boneprint to a Vue 3 app built with Vite."
canonical_url: "https://kukson777.github.io/boneprint/docs/getting-started/vue"
---
# Vue + Vite

> Add Boneprint to a Vue 3 app built with Vite.

## Install

<code-group>

```bash [npm]
npm install boneprint
```

```bash [pnpm]
pnpm add boneprint
```

```bash [yarn]
yarn add boneprint
```

```bash [bun]
bun add boneprint
```

</code-group>

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:

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

## Register globally

```ts [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](https://kukson777.github.io/boneprint/docs/api/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`:

<code-group>

```ts [vite.config.ts]
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'] }] }),
  ],
})
```

```ts [vite.config.ts (Nuxt UI)]
import ui from '@nuxt/ui/vite'
import { boneprintResolver } from 'boneprint/resolver'

// ui() runs unplugin-vue-components and unplugin-auto-import itself
export default defineConfig({
  plugins: [
    vue(),
    ui({
      components: { resolvers: [boneprintResolver()] },
      autoImport: { imports: ['vue', { boneprint: ['forgetSkeletons', 'useInSkeleton'] }] },
    }),
  ],
})
```

</code-group>

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:

```vue
<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](https://kukson777.github.io/boneprint/docs/guide/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.


## Sitemap

See the full [sitemap](https://kukson777.github.io/boneprint/sitemap.md) for all pages.
