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.

Adding images to /dist

See original GitHub issue

Prefacing this issue by saying that this is an awesome repo. Everything save for this issue has been relatively straightforward to come to grips with and understand! Cheers! @coryhouse!!

My issue is that I have a directory in src called images (src/images) which contain all my image assets. When I try to access these via the npm run start command, it works fine. I simply access the file like so:

<img className="auth-logo" src="images/joyglobal_logo.png" />

The issue is when I run npm run build… This path src/images does not seem to be accessed by the build task and dropped into the dist directory.

Any guidance would be tremendous!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremyadaviscommented, May 13, 2016

My app hasn’t kept with the latest slingshot releases so it wouldn’t help to show my webpack, but you would just add the following to the end of the plugins array in webpack.config.prod.js:

new CopyWebpackPlugin([
                                            { from: 'src/assets' }
                                         ])

Just don’t forget to npm install copy-webpack-plugin --save-dev and add import CopyWebpackPlugin from 'copy-webpack-plugin'; to the top of the file.

That said @coryhouse’s example is the best way to handle it so try to stick with require/importing them if you can. There’s a lot more webpack magic that can happen when using file-loader.

0reactions
lorenzoidcommented, May 12, 2016

Thanks @coryhouse!

@jeremyadavis, thanks as well! Would you mind sharing an example? New to webpack so I wanted to know where to implement copy-webpack-plugin exactly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack is not copying images to dist folder - Stack Overflow
My project copies my fonts correctly but not images. Now the only way I am able to make it work is by copying...
Read more >
Managing Images with webpack - LearnHowToProgram.com
For that reason, we need to use webpack to manage images and correctly add them to our dist directory. Configuring webpack for Images....
Read more >
Copy all images/files to a folder using copy-webpack-plugin
In such cases, we can configure webpack to copy all our image resources to the dist folder using 'CopyWebpackPlugin'. With images copied to...
Read more >
Link Images from "Dist" folder to the JS file - Roots Discourse
I am using Sage 9, I want to put some image links to the JS file, but not sure how to link the...
Read more >
Optimizing Static HTML And Images With Webpack
Webpack doesn't know how to handle HTML files, but adding the html-webpack-plugin ... finds all static html files and outputs them to the...
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