question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Values in vue templates don't trigger auto-import

See original GitHub issue

If looking at the template itself isn’t a good idea, perhaps some dev-facing comment directives or config options to set more limited matching for specific use cases could be helpful.

To give an example. I can do the following, but I have to add the variable names to something in the script block for it to work, which kind of defeats the purpose.

AutoImport({
	imports: [
		'vue',
                {
                	'@mdi/js': Object.keys(await import('@mdi/js')).filter(v=>v.startsWith('mdi')),
                }
	],
}),
<script setup lang="ts">
// Ideally I wouldn't end up with having to write out import statements with 12+ different variables
// but to get them to auto-import, I've got to do something like this:
const i = {mdiInformationOutline}

// And I can't just do `import * as i from '@mdi/js'` because then it doesn't get tree shook, and I end up with 2MB+ file
</script>
<template>
  <main class="px-4 py-10 text-center text-teal-700 dark:text-gray-200">
    <div>
      <p class="text-4xl">
        <v-icon :icon="i.mdiInformationOutline" class="inline-block" />
      </p>
    </div>
    <router-view />
  </main>
</template>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
antfucommented, May 24, 2022

Shipped in v0.8.0

0reactions
websitevirtuosocommented, Sep 22, 2022

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

antfu/unplugin-vue-components: On-demand ... - GitHub
Use components in templates as you would usually do, it will import components on demand, and there is no import and component registration...
Read more >
Auto-import VueJs components while coding at SublimeText
I've tried installing ImportJs and AutoImport plugins for Sublime, but for my understanding they only work for .js or .ts files. Is there...
Read more >
Vue 3: Support new <script setup> without ref sugar - YouTrack
no auto import when new component is being added through <template>; can't CMD+click open component from <template> when using this new <script setup>....
Read more >
Common mistakes to avoid while working with Vue.js
Common mistakes to avoid while working with Vue.js · Include template compiler · Keep property's reactivity · Be careful with SFC exports ·...
Read more >
Component Registration - Vue.js
A Vue component needs to be "registered" so that Vue knows where to locate its implementation when it is encountered in a template....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found