Skip to content

Allow ~/path as <img src="~/..."> with ~ alias #13460

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

Open
OrbisK opened this issue Jun 10, 2025 · 3 comments · May be fixed by #13462
Open

Allow ~/path as <img src="~/..."> with ~ alias #13460

OrbisK opened this issue Jun 10, 2025 · 3 comments · May be fixed by #13462
Labels
✨ feature request New feature or request

Comments

@OrbisK
Copy link
Contributor

OrbisK commented Jun 10, 2025

Vue version

3.5.16

Link to minimal reproduction

https://github.com/OrbisK/vue-img-src-tilde

Steps to reproduce

  1. pnpm i
  2. pnpm dev
  3. Error. The first '~' is always stripped.

What is expected?

The first ~ should not be stripped.

What is actually happening?

export function parseUrl(url: string): UrlWithStringQuery {
const firstChar = url.charAt(0)
if (firstChar === '~') {
const secondChar = url.charAt(1)
url = url.slice(secondChar === '/' ? 2 : 1)
}
return parseUriParts(url)
}

This does always remove the first ~

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 36.29 GB / 62.58 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 23.5.0 - ~/.nvm/current/bin/node
    npm: 10.9.2 - ~/.nvm/current/bin/npm
    pnpm: 8.15.9 - ~/.nvm/current/bin/pnpm
    bun: 1.1.42 - ~/.nvm/current/bin/bun
  Browsers:
    Chrome: 130.0.6723.69
  npmPackages:
    vue: ^3.5.13 => 3.5.16

Any additional comments?

Nuxt uses ~ as alias for the /app directory.

Ref: vitejs/vite-plugin-vue#15
Ref: nuxt/nuxt#32119 (comment)

/cc @danielroe

@edison1105
Copy link
Member

This would be a breaking change.

Currently

<img src="~/fixtures/logo.png"/>

is compiled to

import _imports_0 from 'fixtures/logo.png'

@danielroe
Copy link
Member

danielroe commented Jun 10, 2025

would it be possible to distinguish ~/assets/test.png and ~assets/test.png (the latter is the example in the docs, which makes more sense for accessing a module)?

or, alternatively, make this behaviour configurable?

@edison1105
Copy link
Member

edison1105 commented Jun 11, 2025

I agree with making this behavior configurable and made a PR #13462.
Any suggestions are welcome.

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

Successfully merging a pull request may close this issue.

3 participants