Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit d846e3a

Browse files
committed
Fix root-relative url()s in output when there's no browserRootURL
This is the problem pointed out by @montoriusz in #135 (comment)
1 parent 5a840b7 commit d846e3a

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

css-plugin-base-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
122122
}
123123
}), atUrl({
124124
url: function(fileName, decl, from, dirname, to, options, result) {
125-
if ((absUrl(fileName) && fileName.charAt(0) !== '/') || fileName.match(/^%23/))
125+
if ((absUrl(fileName) && (!loader.browserRootURL || fileName.charAt(0) !== '/')) || fileName.match(/^%23/))
126126
return fileName;
127127

128128
// dirname may be renormalized to cwd

test/css.builder.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ describe('CSS Builder', function() {
5151
});
5252
});
5353

54+
// https://github.com/systemjs/plugin-css/pull/135#commitcomment-24415595
55+
it('should handle a root-relative url when no rootURL and no browserRootURL are configured', function () {
56+
var builder = new Builder();
57+
builder.config(System.getConfig());
58+
return builder.compile('test/data/rootRelative.css!', {minify: false}).then((results) => {
59+
return expect(results.source).to.contain("body{background-color:red;background-image:url(/path/to/x.png)}");
60+
});
61+
});
62+
5463
it('Should support buildCSS: false', function() {
5564
var builder = new Builder();
5665
builder.config(System.getConfig());

0 commit comments

Comments
 (0)