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

Using url(path) with resolve.alias #49

Closed
SimenB opened this issue May 4, 2015 · 7 comments
Closed

Using url(path) with resolve.alias #49

SimenB opened this issue May 4, 2015 · 7 comments

Comments

@SimenB
Copy link
Contributor

@SimenB SimenB commented May 4, 2015

I have a few images in a shared location, which I import in a css file. This shared location has a lot of code shared between 5 webapps within the same project, and I have defined the alias common-assets in my config, which works great for every asset/module, except for css. The path is normalized by css-loader (I think?) to be relative, which breaks.

Is there any clean way to use the alias, or do I have to go url("../../../../../../../../common/assets/images/image.png") instead of the much cleaner url("common-assets/images/image.png")? If I do the latter, the actual import becomes url("./common-assets/images/image.png"), which is wrong, and fails the build.

@SimenB SimenB changed the title Using url(path) with alias Using url(path) with resolve.alias May 4, 2015
@sokra
Copy link
Member

@sokra sokra commented May 4, 2015

https://github.com/webpack/css-loader#usage

url("~common-assets/images/image.png")

@SimenB SimenB closed this May 4, 2015
@SimenB
Copy link
Contributor Author

@SimenB SimenB commented May 4, 2015

Ah, of course, that makes sense.
I was thinking that it only resolved modules (i.e. from node_modules),
but that it resolves things like modules makes much more sense.
Thanks!

@cj
Copy link

@cj cj commented Mar 16, 2016

@sokra I tried this but I'm getting an error http://prntscr.com/afub2r am I missing something?

@cj
Copy link

@cj cj commented Mar 16, 2016

I actually think this is a postcss/postcss-import issue, I've created a ticket there.

@mrdulin
Copy link

@mrdulin mrdulin commented Dec 17, 2016

@sokra url("~common-assets/images/image.png") worked. But what's the meaning of ~ symbol?

@SimenB
Copy link
Contributor Author

@SimenB SimenB commented Dec 17, 2016

It means that it's a module and not a relative path

@j-u-p-iter
Copy link

@j-u-p-iter j-u-p-iter commented Jul 8, 2018

Pretty cool! Is this documented somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants