systemjs / plugin-css

CSS loader plugin
MIT License
92 stars 60 forks source link

Bug with absolute urls in CSS or misconfiguration at my end? #137

Open rj33 opened 6 years ago

rj33 commented 6 years ago

I'm a bit confused by the consequences of this code in css-plugin-base-builder.js

url: function(fileName, decl, from, dirname, to, options, result) {
      if ((absUrl(fileName) && fileName.charAt(0) !== '/') || fileName.match(/^%23/))
        return fileName;

I'm having trouble with absolute font paths being rewritten by the CSS plugin when bundling, so I have a font-face definition that looks like:

@font-face {
    font-family: 'ChessAlphaRegular';
    src: url('/fonts/chessalphanew-webfont.vers1.eot');
    src: url('/fonts/chessalphanew-webfont.vers1.eot?#iefix') format('embedded-opentype'),
         url('/fonts/chessalphanew-webfont.vers1.woff') format('woff'),
         url('/fonts/chessalphanew-webfont.vers1.ttf') format('truetype'),
         url('/fonts/chessalphanew-webfont.vers1.svg#ChessAlphaRegular') format('svg');
    font-weight: normal;
    font-style: normal;
    unicode-range: U+0042,U+004B,U+004E,U+0051,U+0052;
}

I'd like to keep those absolute paths as they are during processing, but the fileName.charAt(0) !== '/' is overriding the result of the absUrl test, and the code falls through to code that is transforming my absolute URL into one that is relative to the tree the bundle is being built into. Is this intended behaviour? Should I be setting rootURL to something to avoid this transformation of absolute URLs? It looks like I could avoid the absolute manipulation by making the path https://hostname.com/fonts/etcetc, but I'd really rather avoid that.