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 for /@/ not work properly #1363

Closed
hronro opened this issue Jan 5, 2021 · 10 comments
Closed

alias for /@/ not work properly #1363

hronro opened this issue Jan 5, 2021 · 10 comments

Comments

@hronro
Copy link
Contributor

hronro commented Jan 5, 2021

Describe the bug

Alias for /@/ not working properly. It works in v1.

Reproduction

https://github.com/foisonocean/vite2-alias-bug

System Info

  • required vite version: 2.0.0-beta.5
  • required Operating System: Linux
  • required Node version: v15.5.0
  • Optional:
    • yarn version: 1.22.10
@Ttou
Copy link

Ttou commented Jan 5, 2021

可以试试 vite-tsconfig-paths,有支持 2.0 的版本

@MQYForverT

This comment has been minimized.

@wangguo1230
Copy link

可以使用[
{
find: "/@",
replacement: pathResolve("./src"),
},
]

@LoveofRedMoon
Copy link

已经提过issue给rollup-plugin了, 目前可以修改为'/@'避免问题

@yyx990803
Copy link
Member

这个 issue 跟其他的 alias 问题没有任何关系,只是 alias 不作用于 HTML 里的 url 而已。

2.0 的 alias 是直接替换,所以如果你用了 /@/ 这样的 alias 那么值也需要有 / 结尾。https://vitejs.dev/guide/migration.html#alias-behavior-change

@hronro
Copy link
Contributor Author

hronro commented Jan 6, 2021

/@/ still not work in vite@2.0.0-beta.9, it seems like a upstream bug from @rollup/plugin-alias (rollup/plugins#759).

{
  alias: {
    // not work
    '/@/': path.resolve(__dirname, 'foo') + '/',
    // works
    '/@': path.resolve(__dirname, 'foo'),
  },
}

@liwenfengg
Copy link

这个 issue 跟其他的 alias 问题没有任何关系,只是 alias 不作用于 HTML 里的 url 而已。

2.0 的 alias 是直接替换,所以如果你用了 /@/ 这样的 alias 那么值也需要有 / 结尾。https://vitejs.dev/guide/migration.html#alias-behavior-change

尤大哥, alias 不作用于 HTML 里的 url 这个问题 什么时候可以修复啊?

@qq31311137
Copy link

const alias: Record<string, string> = {
    '/@': resolve(__dirname, './src'),
    '/@views': resolve(__dirname, './src/views'),
    '/@components': resolve(__dirname, './src/components'),
    '/@images': resolve(__dirname, './src/assets/images'),
    '/@icons': resolve(__dirname, './src/assets/images/icons'),
}

HTML 文件里面 alilas 不生效
在 TS 文件里面是可以的

@qq31311137
Copy link

@foisonocean 大哥 vite2 alias 在 html 文件可以生效吗

@hronro
Copy link
Contributor Author

hronro commented Jan 22, 2021

@qq31311137 It works for me.

@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.
Projects
None yet
Development

No branches or pull requests

8 participants