Giter VIP home page Giter VIP logo

Comments (6)

jirikolarik avatar jirikolarik commented on April 20, 2024

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]' }

from react.

jirikolarik avatar jirikolarik commented on April 20, 2024

Give me second, I'll prepare you a demo

from react.

jirikolarik avatar jirikolarik commented on April 20, 2024

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

from react.

dbhandel avatar dbhandel commented on April 20, 2024

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.

from react.

jirikolarik avatar jirikolarik commented on April 20, 2024

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

npm i file-loader --save

from react.

dbhandel avatar dbhandel commented on April 20, 2024

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.

from react.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.