Adding images to /dist
See original GitHub issuePrefacing 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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Just don’t forget to
npm install copy-webpack-plugin --save-dev
and addimport 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.
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.