question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image url not correct in HMR

See original GitHub issue
  • Laravel Mix Version: 0.12.1 (npm list --depth=0)
  • Node Version (node -v): v7.10.0
  • NPM Version (npm -v): 5.0.0
  • OS: OSX

Description:

In HMR, using <img src="../../images/logo.png"> in the .vue file can’t load image in browser. the image url is /images/logo.png?[hash].

I think image url must be http://localhost:8080/images/logo.png?[hash] in HMR.

Steps To Reproduce:

  1. app.js
window.Vue = require('vue');

Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
    el: '#app'
});
  1. Example.vue
<template>
    <div class="container">
        <img src="../../images/logo.png" />
    </div>
</template>

<script>
    export default {
    }
</script>
  1. Add logo.png to directory

  2. run npm run hot

Result

screen shot 2017-06-01 1 59 15

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
pyrostrexcommented, Nov 9, 2017

How is this not documented yet? Thanks @CasperLaiTW , Anyhoo in the latest laravel-mix/webpack, i had remove the .options to get it to work. In case anyone wondering…

if (mix.config.hmr) {
    mix.setResourceRoot('//localhost:8080/');
}
4reactions
CasperLaiTWcommented, Jun 1, 2017

Thanks @ruchern

If I use npm run production it’s all working. image will be processed to public/images/ automatic

if I remove publicPath from loader or setup resourceRoot to be //localhost:8080/ - it’s working in HMR.

https://github.com/JeffreyWay/laravel-mix/blob/v0.12.1/setup/webpack.config.js#L179

so my workaround is

if (mix.config.options.hmr) {
    mix.setResourceRoot('//localhost:8080/');
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Image url not correct in HMR #845 - laravel-mix ... - GitHub
In HMR mode, new images are served in webpack dev server, but the generated urls point to Laravel server. I think the solution...
Read more >
can't load images when using webpack-dev-server with HMR ...
First in your webpack config, your file loader for images is: ['file-loader?name=/img/[name].[ext]'] , which will output images to ...
Read more >
Handling Images - Medium
For the image's location, you either provide the URL of the image or the relative path location of the image if its stored...
Read more >
Image url is not working properly
So I had created a image url in column, but the issue is if nothing is selected then the 1st image in the...
Read more >
Static Asset Handling - Vite
url () references in CSS are handled the same way. If using the Vue plugin, asset references in Vue SFC templates are automatically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found