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
html image src require not respecting webpack aliases? #193
Comments
|
<img class="logo" src="~assets/logo.png"> |
|
Not directly related, but if you're using the vue-cli webpack boilerplate and webpack is giving you pain when trying to bind images from the default data object (or whatever this is called, my first Vue project)..:
|
|
@k1sul1 I tried this solution but I am getting error |
|
Well, if you actually read the error message, you might actually figure it out :) It clearly says "Cannot find module", so your path is probably broken. Meaning the file doesn't exist in that location :) |
|
@k1sul1 ok please don't think I am posting this before checking something like that... Ofcourse it exists... For example this is working:
while this is not with the error I posted above |
|
Interesting. Can't say I have any ideas other than adding Could be a platform issue, are you using Windows perhaps? For me, |
|
@k1sul1 tried that too when I noticed I don't have one, but without any luck. We are discussing this on the Vue.js forum as well but no success right now http://forum.vuejs.org/topic/5343/webpack-serve-dynamic-images/15. |
|
thx~ |
|
this code... is returning:
|
|
no more, changed to |
|
thanks @oswaldomilet <img src="~@/assets/logo.png" />worked for me. Very weird... |
Load assets with alias path.
|
my solution! 1. |
|
I have another a way:
|
|
Not all heroes wear capes. Thanks @oswaldofreitas The future generations will remember you. |
|
hahaha, funny. Thanks @jofftiquez |
|
In my case it works with url('~@/assets/.......png') |
|
@paladin2005 you mean it WORKS or DOES NOT? |
|
@jofftiquez I already edited y last comment. Sorry my english. |
|
In data(){return{require()}},how to writh this path |
|
write this |
|
Or in css url(~) ? |
This |
@jofftiquez weird, I'm trying the same thing and getting an error. ERROR Failed to compile with 1 errors |
<img class="logo" src="~assets/logo.png">why use "~", it will work. I want to kown the reason |
|
@oswaldofreitas you are the man |
|
If you are using data property to assign image to src, then use require(<image_path>). Like,
|
|
Another solution that I am using is |
|
does anyone know how to npm install the package in order to use REQUIRE in the client application ? I forgot what package that is |
worked for me too. |

alexbakerdev commentedMar 30, 2016
Hey there,
I'm new to vue (which I love so far), just setting up an example project.
Hoping someone can tell me where I'm going wrong with aliasing requires.
Using the vue-cli webpack template for example, changing App.vue template to
and webpack.base.conf.js
Then moving App.vue into the folder
src/App/as index.vue webpack.npm run buildgives:
Not sure what is going on here the image seems to be taken care of by url-loader as its encoded into the js. Which I think differentiates it from this issue #172 which Evan already replied to.
The text was updated successfully, but these errors were encountered: