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

How to change image url for subfolder projects? #69

Open
codestitch opened this issue Feb 17, 2017 · 4 comments
Open

How to change image url for subfolder projects? #69

codestitch opened this issue Feb 17, 2017 · 4 comments
Labels

Comments

@codestitch
Copy link

Hi.

In my HeaderComponent (located in src/components/navigation/) this is what it looks like when i include an image from images folder let yeomanImage = require('../../images/logo.png'); then use it <img className='img-header' src={yeomanImage}/>. It runs fine in dev server.

Now when I compiled my project to production. I changed my index.html in /dist folder from <script type="text/javascript" src="/assets/app.js"></script> to this <script type="text/javascript" src="./assets/app.js"></script>.

When I run the compiled project it can't seem to find the image.

capture

How do I change my require in getting the image?

Thanks for your help.

Cheers!

@stylesuxx
Copy link
Owner

Hey,
can you tell me which URL is used for the src tag of the image on prod?

Will need to take a look at this.

@raza2022
Copy link

raza2022 commented Apr 4, 2017

@codestitch have you soled it?
@stylesuxx i stuck with same situation and tried many solution but none of these works
reproduce i have a image named graph-left_03.png in my images folder
i tried 3 way all working in serve but not in direct dist

  • just give it <img src="images/graph-left_03.png" /> not working in dist

  • //images link
    const graphLeft3 = require('../../images/graph-left_03.png');
    <img src={graphLeft3} /> still not working in dist

  • i just copied the images folder in dist but it also want resolve with both ./ and ./../
    Thanks

@codestitch
Copy link
Author

Hi. since my project is deployed in sub folder here are the following changes that i did for the images to work properly.

  1. Go to

cfg/default.js

and change publicPath: '/assets/', to publicPath: './assets/',

  1. After running npm run dist change index.html in

dist/index.html

from src="/assets/app.js" to src="./assets/app.js"

@raza2022
Copy link

raza2022 commented Apr 5, 2017

@codestitch Thanks i just added ./ after making dist in every link (two one for favicon and one app.js)

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

No branches or pull requests

3 participants