Skip to content

import as ?component in <script>, but as ?url in <template> #153

Description

@mrleblanc101

Hi,
Would it be possible to auto-detect where the import is from, and change the defaultImport accordingly ?
For exemple, in a Vue SFC, if I import inside the <script> tag, I always want to import as a component like so:

<script setup>
import IconDelete from '@/assets/icon/delete.svg'
</script>

<template>
    ...
    <IconDelete width="24" height="24" />
    ...
</template>

But if I import from the template, I want it to be imported as an url, like so:

<template>
    <img src="@/assets/img/someComplexGraphic.svg" />
</template>

Currently, we have set our defaultImport to url, and manually add ?component to every import inside our script tags like so if we want both behavior to work:

<script setup>
import IconDelete from '@/assets/icon/delete.svg?component'
</script>

<template>
    ...
    <IconDelete width="24" height="24" />
    <img src="@/assets/img/someComplexGraphic.svg" />
    ...
</template>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions