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

What is the best method fo loading static resources? #18

Closed
dbhandel opened this issue Feb 10, 2016 · 6 comments
Closed

What is the best method fo loading static resources? #18

dbhandel opened this issue Feb 10, 2016 · 6 comments

Comments

@dbhandel
Copy link

Hi,
I'm trying to load a logo.png file. I created a directory /public/images. I have attempted to use github: tcoopman/image-webpack-loader although I may have misused this or it may not be the correct loader.

Do you have any guidance on how to load images using your boilerplate?

Thanks

@jirikolarik
Copy link
Member

Hey,

sure thing.

You can use https://github.com/webpack/file-loader and loader to web pack config

{ test: /\.(png|jpg|svg)$/, loader: 'file?name=/[name]-[hash].[ext]' }

@jirikolarik
Copy link
Member

Give me second, I'll prepare you a demo

@jirikolarik
Copy link
Member

Checkout git diff here: https://github.com/werein/react/compare/feature/images

@dbhandel
Copy link
Author

Thanks Jiri. Your instructions are crystal clear but I get this error:

Module parse failed: /Users/davidhandel/code/idr/src/public/images/logo.png Line 1: Unexpected token ILLEGAL
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
@ ./src/components/LoggedInHeader.js 31:12-48

I have a png file loaded in logo.png. I have placed your loader in my webpack.development.js. All I see is a broken image in the browser.

@jirikolarik
Copy link
Member

It says that you need a loader which I forgot to save in packages.json

npm i file-loader --save

@dbhandel
Copy link
Author

For whatever reason, the loader code didn't work for me in Webpack config but when I used it in the component like this:
const logo = require('file?name=/images/[name]-[hash].[ext]!../public/images/logo.png');

I could successfully render the logo with an img tag with src={logo} ,

Many thanks.

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

No branches or pull requests

2 participants