From 0d11dadd28e423ce4d320734fd79db6a01e7d87c Mon Sep 17 00:00:00 2001 From: "Derek W. Stavis" Date: Sun, 3 Sep 2017 04:49:57 -0300 Subject: [PATCH] add option to prepend ./ to rebased urls --- README.md | 6 ++++++ src/type/rebase.js | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 135c757..9ba36f3 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ Checkout [tests](test) for examples. ### Options combinations * `rebase` - _default_ + * `relative` - prepend a `./` in front of rebased path * `inline` * `basePath` - path or array of paths to search assets (relative to `from`, or absolute) * `encodeType` - `base64`, `encodeURI`, `encodeURIComponent` @@ -181,6 +182,11 @@ Custom transform function. Takes following arguments: And should return the transformed url. You can use this option to adjust urls for CDN. +#### `relative` +_(default: `false`)_ + +Specifies if a `./` should be prepended to rebased path. + #### `maxSize` _(default: `14`)_ diff --git a/src/type/rebase.js b/src/type/rebase.js index e141db9..4335b19 100644 --- a/src/type/rebase.js +++ b/src/type/rebase.js @@ -9,13 +9,15 @@ const normalize = require('../lib/paths').normalize; * @type {PostcssUrl~UrlProcessor} * @param {PostcssUrl~Asset} asset * @param {PostcssUrl~Dir} dir + * @param {PostcssUrl~Option} options * * @returns {String|Undefined} */ -module.exports = function(asset, dir) { +module.exports = function(asset, dir, options) { const rebasedUrl = normalize( path.relative(dir.to, asset.absolutePath) ); + const relative = options.relative ? './' : ''; - return `${rebasedUrl}${asset.search}${asset.hash}`; + return `${relative}${rebasedUrl}${asset.search}${asset.hash}`; };