Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: support transform alias #324

Open
4 tasks done
Simon-He95 opened this issue Dec 26, 2023 · 2 comments
Open
4 tasks done

feature request: support transform alias #324

Simon-He95 opened this issue Dec 26, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@Simon-He95
Copy link

Description

image image

In background-image: path in url(), the resource will not be parsed correctly

Suggested solution

When compiling a file, automatically convert the alias path of alias into the corresponding target path.

Alternative

No response

Additional context

No response

Validations

@sapphi-red sapphi-red transferred this issue from vitejs/vite Dec 30, 2023
@s3xysteak
Copy link

I am also paying attention to this feature, which will really improve the DX a lot.

before

<script setup>
import FooBar from '~/assets/foo/bar.png'
import PublicAssets from '~pub/publicAssets.png' // /publicAssets.png
</script>

<template>
  <img src="../../../assets/foo/bar.png" >
  <img :src="FooBar" >
  <img :src="PublicAssets" >
</template>

after

<template>
  <img src="~/assets/foo/bar.png" >
  <img src="~pub/publicAssets.png" >
</template>

@sxzz sxzz added enhancement New feature or request and removed enhancement: pending triage labels Jul 15, 2024
@sxzz sxzz changed the title feat: support transform alias feature request: support transform alias Jul 15, 2024
@s3xysteak
Copy link

Refer to the mini repro https://stackblitz.com/edit/vitejs-vite-wokm83?file=src%2FApp.vue

Actually it has support alias now. <img src="@/assets/vite.svg" > could work in the mini repro.

However, <img src="~/assets/vite.svg" > could not work and will throw error. I made a plugin to log the code transformed and found that:

  • src="@/assets/vite.svg" will be transformed to import _imports_0 from '@/assets/vite.svg'
  • src="~/assets/vite.svg" will be transformed to import _imports_0 from 'assets/vite.svg'.

Because @vue/compiler-sfc removed ~/ in the template while compiling.

Is there anything we can do in vite-plugin? Actually, I think this might be an issue with @vue/compiler-sfc, as it causes compilation differences just due to different alias names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants