Coder Social home page Coder Social logo

Require a image in CSS about webpack-howto HOT 5 OPEN

petehunt avatar petehunt commented on May 18, 2024 1
Require a image in CSS

from webpack-howto.

Comments (5)

nkbt avatar nkbt commented on May 18, 2024 1

@sibelius webpack does not process html files and <img> sources won't work.
Id you use React, you do <img src={require('../../img.jpg')} />, if you use some templating language you will need to pass JS variable like:

const imgSrc = require('../../img.jpg');

// ....

// some kind of template
render(`
  <img src="%imgSrc%" />
`)

in angular you would use scope/this

$scope.imgSrc = require('../../img.jpg');

//....

// template.html
<img="imgSrc" />

And so on.

Just remember, that webpack simply returns string from require statement with files/images with correct path to automatically generated file, so you are then free to use it in any way your templating allows you.

from webpack-howto.

nkbt avatar nkbt commented on May 18, 2024

just

content: url("./glyph.png");

You will need to use url-loader, webpack will do all the rest.

See https://github.com/nkbt/esnext-quickstart/blob/master/webpack.config.js#L19-L24 for example

from webpack-howto.

ankitduseja avatar ankitduseja commented on May 18, 2024

Thanks! This is probably the best how-to guide out there.

from webpack-howto.

sibelius avatar sibelius commented on May 18, 2024

@nkbt is this the same for a img src?

because this line: https://github.com/Lar21/webpack-starter-angular/blob/master/src/components/home/home.html#L7

is not working

from webpack-howto.

sibelius avatar sibelius commented on May 18, 2024

@nkbt thanks, this works great! \o/

from webpack-howto.

Related Issues (20)

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.