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

'alias' option dose not work on image's src #1343

Closed
Darcrandex opened this issue Jan 4, 2021 · 8 comments
Closed

'alias' option dose not work on image's src #1343

Darcrandex opened this issue Jan 4, 2021 · 8 comments

Comments

@Darcrandex
Copy link

Darcrandex commented Jan 4, 2021

on 'vite.config.ts'

export default defineConfig({
  alias: { '@': path.resolve(__dirname, './src') },
  plugins: [vue()],
})

then I use the path with 'alias'

// it's ok
<img src="../assets/logo.png" alt="" />
<img src="src/assets/logo.png" alt="" />

// error
<img src="~@/assets/logo.png" alt="" />
<img src="@/assets/logo.png" alt="" />
@dmyz
Copy link

dmyz commented Jan 4, 2021

@Darcrandex

version:vite2

demo:https://github.com/rollup/plugins/tree/master/packages/alias#rollupplugin-alias


alias: [
    {find: '@C', replacement: './components'},
    {find: '@', replacement: resolve(__dirname, './src')},

]

import HelloWorld from '@/components/HelloWorld.vue'

有不对的请及时说明

@phanmn
Copy link

phanmn commented Jan 4, 2021

I tried but not work @dmyz

@yyx990803
Copy link
Member

This is fixed in @vue/compiler-sfc but will require a new release from Vue core.

@hronro
Copy link
Contributor

hronro commented Jan 5, 2021

@yyx990803
How about in vanilla js or other frameworks like React?
In vite v1, when I set {alias: { '/@/': path.resolve(__dirname, './src') }}, I can use something like <script src="/@/index.ts"></script> in HTML, but it seems not works in vite v2.

@yyx990803
Copy link
Member

@hronro
Copy link
Contributor

hronro commented Jan 5, 2021

@yyx990803 Adding an ending slash still not work for me, I will create a new issue later.

@phanmn
Copy link

phanmn commented Feb 6, 2021

This is fixed in @vue/compiler-sfc but will require a new release from Vue core.

Can you please consider to release this version soon @yyx990803, thank you

@mikerockett
Copy link

@yyx990803 Just updated an app that had this issue, and it's almost fixed. In my case, I'm using backend integration. Devserver is served at domain:3000, backend serves at domain. Vite uses :3000 correctly for modules/hmr, but seemingly not for assets. As a result, images are being requested at domain, and not domain:3000. Is there an additional config prop I need to set so that images are loaded with full paths?

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants