Skip to content

Adding background form scss doesn't work #25

Description

@Silver360

When I try add image as background, picture not showing. My code looks like this.

.bg { background-image: url('../assets/section-packets-bg.png'); }

webpack generate this url url("http://localhost:8080/../../assets/section-packets-bg.png")

Activity

  1. lifenautjoe commented on Feb 24, 2019

    @lifenautjoe
    Owner

    Hi @Silver360 , I'll take a look.

    Could you meanwhile try to load it from ./assets/section-packets-bg.png ?

    Cheers.

  2. self-assigned this
    on Feb 24, 2019
  3. NathanHealea commented on Mar 3, 2019

    @NathanHealea

    Hi @Silver360 , Give this a try.

    npm install --save-dev resolve-url-loader
    

    webpack.dev.js

    {
      // translates CSS into CommonJS
      loader: 'css-loader',
      ...
    },
    {
      loader:'resolve-url-loader',
      option: {
        sourceMap: true
      }
    },
    {
      // compiles Sass to CSS
      loader: 'sass-loader'
      ..
    }
    ...
    

    In your sass file use a relative path. In the file structure I'm using I have an image directory under styles
    styles/index.scss

    .bg { background-image: url('img/section-packets-bg.png'); }
    
  4. ldraminski commented on Mar 3, 2019

    @ldraminski

    Hi thanks for replay. When I try install resolve-url-loader I get this message.
    screenshot_1

  5. NathanHealea commented on Mar 14, 2019

    @NathanHealea

    @ldraminski,

    That message indicated that there are vulnerabilities in the package that you installed.
    You can either run npm audit fix or just ignore them.

  6. annelyse commented on Apr 11, 2019

    @annelyse

    Option with a S , if not it doesn't work !

    {
    loader:'resolve-url-loader',
    options: {
    sourceMap: true
    }
    },
    {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions