Open jd-solanki opened 2 years ago
Moreover, if you use script version of dynamicImgImport
:
<script setup>
const avatar1 = dynamicImgImport('@/assets/images/avatars/avatar-1.png')
</script>
<template>
<img :src="avatar1" alt="avatar">
<!-- <img :src="dynamicImgImport('@/assets/images/avatars/avatar-1.png')" alt="avatar" /> -->
<!-- <img :src="dynamicImgImport('@/assets/images/avatars/avatar-2.png')" alt="avatar" /> -->
</template>
it works correctly.
I consider this as a limitation. The auto-import concept is
vueTemplate: true
→ This will generate a declare module '@vue/runtime-core'
part in dts file (also for output of step 1)In your use case, you want to use a func only in vue template and skip the script section.
This will cause 1. parsing source and get all things need to import
fails.(Currently only scan typescript part so vue template will be out of range)
https://github.com/unjs/unimport/blob/2044d7cfd373bb91fc57f548a5c16d895db15832/src/context.ts#L124
so step3 could not know what is the function you are using.
If you really want to do so. I think first keep script like:
<script setup>
const avatar1 = dynamicImgImport('@/assets/images/avatars/avatar-1.png')
</script>
run vite -> this will auto genarate dts file contains vue template usable declaration.
and then change config to dts:false
modify the code back to
<script setup>
//const avatar1 = dynamicImgImport('@/assets/images/avatars/avatar-1.png')
</script>
<template>
<img :src="dynamicImgImport('@/assets/images/avatars/avatar-1.png')" alt="avatar" />
</template>
it should works
Describe the bug
Hi,
Thanks for creating this amazing unplugin. This is very helpful.
We have created a small utility function
dynamicImgImport
which let us import the images without importing them in script block. This is just like therequire
we had in vue 2.The Problem
The problem I am facing is really weird. Sometimes it imports the
dynamicImgImport
and renders the image correctly and sometimes it just throws an error like the below:Error on stackblitz:
Reproduction
https://stackblitz.com/github/jd-solanki/unplugin-auto-import-demo?file=README.md https://github.com/jd-solanki/unplugin-auto-import-demo
System Info
Used Package Manager
yarn
Validations