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 BUG #2316

Closed
chdjj opened this issue Mar 1, 2021 · 9 comments · Fixed by #2323
Closed

alias BUG #2316

chdjj opened this issue Mar 1, 2021 · 9 comments · Fixed by #2323
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@chdjj
Copy link

chdjj commented Mar 1, 2021

Describe the bug

在对于被使用别名引入的scss文件,在被引入的这个文件中所使用别名引入的静态文件没有被替换为正确的路径。

Reproduction

github链接

System Info

  • vite version: 2.0.1
  • Operating System: Mac OS 10.12
  • Node version: v13.14.0
  • Package manager (npm/yarn/pnpm) and version: npm/6.14.4
@HomyeeKing

This comment has been minimized.

@chdjj
Copy link
Author

chdjj commented Mar 3, 2021

you should append the extension

I try append the extension, But not yet。

resolve: {
    alias: [
      { find: "@", replacement: path.resolve(__dirname, './src') },
      { find: "~sass", replacement: path.resolve(__dirname, './src/assets/sass') },
      { find: "~assets", replacement: path.resolve(__dirname, './src/assets') }
    ],
    extensions: ['.js', '.vue', '.json', '.scss', '.css']
  }

The path did not load properly

console:

GET http://localhost:3000/assets/sass/~assets/logo.png 404 (Not Found)

@HomyeeKing

This comment has been minimized.

@chdjj
Copy link
Author

chdjj commented Mar 3, 2021

@import "~sass/app.scss";

Loading SCSS file is normal,
But I want to use aliases in the SCSS file as well.
Use @import "~sass/app.scss"; is not working,
But use @import "./assets/sass/app" is normal.
I think it's a bug.

@HomyeeKing
Copy link
Contributor

using url() to rebase the url can solve this
but I am not sure whether this is a bug with bare @import

@xiaohulu
Copy link

xiaohulu commented Mar 9, 2021

I also have this bug.

I use path alias.

<style lang="scss" scoped>
@import "/@/assets/styles/variables.scss";

</style>

throw errors

[plugin:vite:css] Can't find stylesheet to import.
  ╷
2 │ @import "/@/assets/styles/variables.scss";
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵

user relative path works.

<style lang="scss" scoped>
@import "../../assets/styles/variables.scss";

</style>

node: 14.16.0
npm: 7.6.0
vite: 2.0.5
vue: 3.0.7

@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Mar 22, 2021
crcong added a commit to crcong/vite that referenced this issue Mar 24, 2021
@xiaohulu
Copy link

Still Can't find stylesheet to import when I update to vite 2.1.3

@patak-dev
Copy link
Member

@xiaohulu would you open a new issue with a minimal reproduction against vite 2.1.3? Thanks!

@fabd
Copy link

fabd commented Mar 31, 2021

Thanks for the bug fix, I also came across this earlier. 👍

Now, in sass I can use the tilde aliases in eg. @import '~styles/foo or background: url("~assets/images/foo.gif").

However in a .vue template image file, the tilde doesn't work : eg. <img src="~assets/images/logo-rune.png" ...

Using an at symbol style of alias like @assets/... works in both vue <img src="@assets/images/logo-rune.png" and scss file: background: url("@images/rune-bg2.gif") ...`

I imagine the ~ tilde style alias doesn't work in .vue file because it's considered to be a node_module right?

So am I correct in saying then, that as best practice, weŕe better off to just always use at symbole style aliases if they work in both cases ? ( eg. @assets )|

Is there any point to using tilde alias if it doesn't have a consistent behaviour betweenm vue and sass imports?

@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
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
6 participants