Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

sourceMap css does not function for background-image (maybe stylus-loader issue) #29

Closed

Description

@nmccready

So this issue is bizarre and I hope I can make an example that does this.

I successful got sourceMaps to work with stylus-loader with
{ test: /\.styl$/, loader: 'style!css?sourceMap!stylus' }

However when ?sourceMap is enabled all our background url('whatever/sprite.png') no longer work. When the ?sourceMap is removed all is well.

I will make an example repo when I get the chance. Also let me know if this should be an issue on stylus-loader instead.

As for more info the css produced are identical except that sourcemap css is redirected via @import some url. The computed CSS reported by Chrome Debugger is identical, but using (Chrome Extension) CSSViewer reports different processed CSS. Which shows the missing sprite.

Also this problem exists in Firefox as well so I do not think it is a chrome issue.

Activity

  1. changed the title [-]sourceMap css does not function for background-image[/-] [+]sourceMap css does not function for background-image (maybe stylus-loader issue)[/+] on Dec 17, 2014
  2. sokra commented on Dec 27, 2014

    @sokra
    Member

    The problem is that DataUrls cannot download resources... (The stylesheet is embedded as DataUrl to append the SourceMap)

    As workaround you could include every image as DataUrl (with the url-loader instead of the file-loader)...

    I'll try to find a better solution...

  3. nmccready commented on Jan 13, 2015

    @nmccready
    Author

    Thank you.

  4. sokra commented on Apr 9, 2015

    @sokra
    Member

    I'll try to find a better solution...

    URL.createObjectURL + Blob + sourceMappingURL does work.

  5. nmccready commented on Apr 9, 2015

    @nmccready
    Author

    Its been a while; how would this look in the config?

  6. sokra commented on Apr 9, 2015

    @sokra
    Member

    style-loader!css-loader?sourceMap

  7. timaschew commented on Jun 19, 2015

    @timaschew

    we are using stylus-loader and all the url paths are not resolved, if the stylus file was called via another module via ~myModule.

    With this settings for the stylus-loader it's working: ?{"resolve url": true}

  8. kevinrenskers commented on Jul 28, 2015

    @kevinrenskers

    I just came across the same issue where background images from css don't work because of the paths, when using sourcemaps, css-loader and file-loader in dev mode with webpack-dev-server.

    For now I've simply disabled sourcemaps, but was there a better fix? style-loader!css-loader?sourceMap was mentioned but this is exactly what's breaking for me.

  9. sokra commented on Jul 28, 2015

    @sokra
    Member

    I think a workaround is to use an absolute URL as output.publicPath.

  10. nmccready commented on Jul 30, 2015

    @nmccready
    Author

    #113 related; tried the pubicPath still didn't work.

  11. nmccready commented on Jul 30, 2015

    @nmccready
    Author

    This issue is also failing with fonts as well. They are being declared as they cannot be decoded in chrome or firefox. Oddly it works fine in safari.

  12. nmccready commented on Jul 30, 2015

    @nmccready
    Author
  13. 2 remaining items

  14. tkiethanom commented on Sep 18, 2015

    @tkiethanom

    Right I am using publicPath: 'http://localhost:9999/' but when I inspect the location of the background-image its chrome-devtools://devtools/public/img/ajax-loader.gif. The original path is /public/img/ajax-loader.gif

    This only happens when sourcemap is on.

  15. AStaroverov commented on Oct 6, 2015

    @AStaroverov

    for me too :(

  16. fingermark commented on Oct 12, 2015

    @fingermark

    Weird. Running into this too when output publicPath isn't set to the full URL.

  17. sokra commented on Oct 15, 2015

    @sokra
    Member

    Setting output.publicPath to an absolute URL should fix the issue, see style-loader README.

  18. mrbinky3000 commented on Mar 28, 2016

    @mrbinky3000

    This still seems to be an issue. Using webpack v1.12.14, css-loader v0.23.1. When sourcemaps are on, background-images will not work. Setting output.publicPath to a full url does nothing to resolve the problem.

  19. evenfrost commented on Jun 8, 2016

    @evenfrost

    I can confirm that setting output.publicPath to a full url fixed the problem for me. My webpack server is hosted on port 5000, my related chunk of config looks as follows:

    output: {
      publicPath: 'http://localhost:5000/',
    },
    module: {
    {
        test: /\.styl$/,
        exclude: /node_modules/,
          loader: 'style!css?sourceMap!stylus?resolve url',
    }, {
        test: /\.css/,
        loader: 'style!css?sourceMap',
      }
    }

    I write Stylus as follows:

    // using file-loader explicitly here as I have svg-inline-loader managing .svg files in config
    background-image url('~!file!assets/patterns/grey.svg')

    It produces following output in generated css:

    background-image: url(http://localhost:5000/95d465435d15b4852261c1b7315c90ba.svg);

    which is proprely seen and parsed by the browser.
    This is the only workflow that works for me. Hope this helps someone.

  20. fingermark commented on Aug 16, 2016

    @fingermark

    Has this been fixed in another ticket? I can't seem to find anything.

  21. liu-dongyu commented on Sep 8, 2016

    @liu-dongyu

    Still facing this problem. I dont want to set an absolute URL like http://... So only thing i can do is to remove the sourceMap

  22. ciasej commented on Sep 11, 2016

    @ciasej

    I am having issues with this as well, hoping for a solution that doesn't involve setting an absolute url on publicPath. Webpack is pretty much useless as build tool in your development workflow if you cannot use source maps to understand what styles are needing to be adjusted when viewing an elements styling.

  23. henrikra commented on Oct 26, 2016

    @henrikra

    Only solution that worked for me was to use sourceMaps with extract-text-webpack-plugin to extract css to own file + change devtool from "eval-source-map" to "source-map".

    Only problem now is that hot reload is veery slow because of high quality source maps. So this is viable only for staging or production environment :)

  24. riccardolardi commented on Dec 3, 2016

    @riccardolardi

    Has this been resolved in the meantime?

  25. kuon commented on Dec 15, 2016

    @kuon

    I faced this issue as well, I disabled source map as absolute URL in public path does not fix the problem.

  26. mhfowler commented on Feb 4, 2017

    @mhfowler

    Hi I'm still having this issue. I was not able to resolve it by setting output.publicPath to an absolute URL either :(

    here is a repository I made demonstrating the problem: https://github.com/mhfowler/Webpack-Example/

    When I remove sourceMap from the css-loader there is no issue.
    But with sourceMap, images set for background-image via url() are unable to load.

    Any help is appreciated, or if you can identify in my webpack config that would be great.
    Here is a link to my webpack config: https://github.com/mhfowler/Webpack-Example/blob/master/webpack.config.babel.js

  27. kisnows commented on Feb 5, 2017

    @kisnows

    @mhfowler The same.

  28. mrdulin commented on Feb 21, 2017

    @mrdulin

    @mhfowler Same issue. enable css module, background-image via url() are unable to load with url-loader, but DataUrl can work.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions