unplugin / unplugin/unplugin-auto-import

Auto import custom directives doesn't works, is it supported?

Open
#369 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.8k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

I defined an custom directives - vEllipsis

composables/ellipsis

import type { ObjectDirective } from 'vue';

export const vEllipsis: ObjectDirective = {
  mounted(el: HTMLElement) {
    el.style.whiteSpace = 'nowrap';
    el.style.overflow = 'hidden';
    el.style.textOverflow = 'ellipsis';
    el.setAttribute('title', el.innerHTML);
  },
};

It works when import vEllipsis,auto import succeed,but it doesn't works.

// app.vue
<script setup lang="ts">
import { vEllipsis } from './composables/ellipsis'; // it works
</script>

<template>
  <div v-ellipsis class="wrap">
    我是很长的一段话我是很长的一段话我是很长的一段话我是很长的一段话我是很长的一段话我是很长的一段话我是很长的一段话
  </div>
</template>
// vite.config.ts
...
AutoImport({
  dts: 'src/auto-imports.d.ts',
  dirs: ['src/composables/**'],
}),
...
Reproduction

https://stackblitz.com/edit/vitejs-vite-p9rpye?file=src%2FApp.vue,src%2Fauto-imports.d.ts,package.json&terminal=dev

System Info
vue: ^3.2.47
vite: ^4.3.0
unplugin-auto-import: ^0.15.2
Used Package Manager

npm

Validations
  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked StackBlitz reproduction and inspect src/auto-imports.d.ts, src/composables/ellipsis, app.vue, and vite.config.ts. Trace how dirs-based auto-imports handle the vEllipsis export and verify whether the generated declaration and transformed component support the v-ellipsis usage. Done means the reproduction works without the explicit import, or the limitation is documented and covered by the relevant project test if one exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.