Skip to content
GitHub

Auto-imports

Use Vue, VueUse, your own utils and components without import statements.

Commonly used APIs are available without an import statement, powered by unimport and unplugin-vue-components. Only what you use ends up in the bundle.

Move the mouse around.

Live preview · No imports in this component Open in new tab ↗
templates/demos/vue/mouse-tracker.visible.ce.vue
<docs lang="ts">
/**
 * Uses auto-imported APIs only: `ref`/`computed` (vue preset),
 * `useMouse` (@vueuse/core preset) and `formatMs` (./js/utils).
 *
 * @element demo-mouse-tracker
 */
</docs>

<script setup lang="ts">
const { x, y } = useMouse()
const startedAt = ref(performance.now())
const uptime = ref(0)

useIntervalFn(() => {
  uptime.value = performance.now() - startedAt.value
}, 100)

const position = computed(() => `${x.value} × ${y.value}`)
</script>

<template>
  <dl class="grid grid-cols-[auto_1fr] gap-x-6 gap-y-2 rounded-lg border border-slate-300 p-4 font-mono text-sm">
    <dt class="text-slate-500">
      useMouse()
    </dt>
    <dd class="m-0">
      {{ position }}
    </dd>
    <dt class="text-slate-500">
      formatMs(uptime)
    </dt>
    <dd class="m-0">
      {{ formatMs(uptime) }}
    </dd>
  </dl>
</template>

What is available

Source Examples
Vue ref, computed, watch, onMounted, …
Pinia defineStore, storeToRefs, …
VueUse useMouse, useIntervalFn, … (except toRef and toValue, which come from Vue)
Alpine.js Alpine (default export of alpinejs)
Your code Every export of a file in js/**, e.g. formatMs from js/utils/formatMs.ts

Components

Components are resolved by name in Vue templates:

  • your *.ce.vue files in js/ and templates/ that have no loading strategy,
  • Headless UI components,
  • VueUse components and directives.

Types

Declarations are generated into .uebertool/unimport.d.ts and .uebertool/components.d.ts, both included by the generated tsconfig.

Configuration

The unimport and components options are deep-merged with the defaults, so arrays such as presets and dirs are extended, not replaced:

vite.config.ts
uebertool({
  unimport: {
    dirs: ['./js/composables/**/*'],
    imports: [{ name: 'gsap', from: 'gsap' }],
  },
})