* Should fix #336.
* For examples regarding root / target / relativeTo take a look at https://github.com/jakubpawlowicz/clean-css/blob/master/test/unit-test.js#L971 - 'urls rewriting - root and target' test.
+[2.3.0 / 2014-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.15...v2.3.0)
+==================
+
+* Allows `target` option to be a path to a folder instead of a file.
+
[2.2.15 / 2014-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.14...v2.2.15)
==================
* `keepBreaks` - whether to keep line breaks (default is false)
* `benchmark` - turns on benchmarking mode measuring time spent on cleaning up
(run `npm run bench` to see example)
-* `root` - path to resolve absolute `@import` rules and rebase relative URLs
-* `relativeTo` - path with which to resolve relative `@import` rules and URLs
+* `root` - path to __resolve__ absolute `@import` rules and __rebase__ relative URLs
+* `relativeTo` - path to __resolve__ relative `@import` rules and URLs
+* `target` - path to a folder or an output file to which __rebase__ all URLs
* `processImport` - whether to process `@import` rules
* `noRebase` - whether to skip URLs rebasing
* `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc.
+var fs = require('fs');
var path = require('path');
var UrlRewriter = require('./url-rewriter');
if (rebaseOpts.absolute)
rebaseOpts.toBase = path.resolve(options.root);
- if (rebaseOpts.relative)
- rebaseOpts.toBase = path.resolve(path.dirname(options.target));
+ if (rebaseOpts.relative) {
+ var target = fs.existsSync(options.target) && fs.statSync(options.target).isDirectory() ?
+ options.target :
+ path.dirname(options.target);
+
+ rebaseOpts.toBase = path.resolve(target);
+ }
if (!rebaseOpts.fromBase || !rebaseOpts.toBase)
return data;
target: path.join(process.cwd(), 'test.css'),
relativeTo: path.join('test', 'data', 'partials-relative')
}),
+ 'urls rewriting - no root but target as a directory': cssContext({
+ 'no @import': [
+ 'a{background:url(../partials/extra/down.gif) no-repeat}',
+ 'a{background:url(test/data/partials/extra/down.gif) no-repeat}'
+ ],
+ 'relative @import': [
+ '@import url(base.css);',
+ 'a{background:url(test/data/partials/extra/down.gif) no-repeat}'
+ ],
+ 'absolute @import': [
+ '@import url(/test/data/partials-relative/base.css);',
+ 'a{background:url(test/data/partials/extra/down.gif) no-repeat}'
+ ]
+ }, {
+ target: process.cwd(),
+ relativeTo: path.join('test', 'data', 'partials-relative')
+ }),
'urls rewriting - root and target': cssContext({
'no @import': [
'a{background:url(../partials/extra/down.gif) no-repeat}',