[3.2.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.1...HEAD)
==================
+* Fixes remote asset rebasing when passing data as a hash.
* Improves path resolution inside source maps.
* Makes `root` option implicitely default to `process.cwd()`.
* Fixed issue [#376](https://github.com/jakubpawlowicz/clean-css/issues/376) - option to disable `0[unit]` -> `0`.
var path = require('path');
var UrlRewriter = require('../images/url-rewriter');
+var REMOTE_RESOURCE = /^(https?:)?\/\//;
+
function SourceReader(context, data) {
this.outerContext = context;
this.data = data;
for (var source in sources) {
var styles = sources[source].styles;
var inputSourceMap = sources[source].sourceMap;
+ var isRemote = REMOTE_RESOURCE.test(source);
+ var absoluteSource = isRemote ? source : path.resolve(source);
+ var absolutePath = path.dirname(absoluteSource);
var rewriter = new UrlRewriter({
absolute: outerContext.options.explicitRoot,
relative: !outerContext.options.explicitRoot,
imports: true,
urls: outerContext.options.rebase,
- fromBase: path.dirname(path.resolve(source)),
- toBase: toBase
+ fromBase: absolutePath,
+ toBase: isRemote ? absolutePath : toBase
}, this.outerContext);
styles = rewriter.process(styles);
assert.equal(minified.styles, '@import url(/partials/one.css);@import url(/partials/extra/three.css);@import url(/partials/extra/four.css);.two{color:#fff}');
}
}
+ },
+ 'with remote paths': {
+ 'topic': new CleanCSS({ sourceMap: true, target: process.cwd() }).minify({
+ 'http://127.0.0.1/styles.css': {
+ styles: 'div{background-image:url(image.png)}'
+ }
+ }),
+ 'gives right output': function (minified) {
+ assert.equal(minified.styles, 'div{background-image:url(http://127.0.0.1/image.png)}');
+ }
}
}
}).export(module);