diff --git a/README.md b/README.md index ed28e3a..c2247a5 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The plugin supports both relative and absolute paths on input file, but can curr | `padding` | The amount of space in pixels to put around images in the sprite. _**Note:**_ This value will be scaled proportionally for retina images. | `20` | | `outputDimensions` | Whether to also output the pixel `height` and `width` of the image. | `false` | | `algorithm` | The [layout algorithm](https://github.com/twolfson/layout) spritesmith should use. | `binary-tree` | +| `outputStylesheetPath` | Optional. Path of the final CSS file. If defined, sprite urls are relative to this path. | `undefined` | ## Input example diff --git a/lib/plugin-options.js b/lib/plugin-options.js index b641c2c..838c389 100644 --- a/lib/plugin-options.js +++ b/lib/plugin-options.js @@ -30,7 +30,10 @@ const pluginOptions = { // If custom options have not been defined by the user, add reasonable // default ones. - this.opts.padding = customOptions.padding || DEFAULT_PADDING; + this.opts.padding = + customOptions.padding === undefined + ? DEFAULT_PADDING + : customOptions.padding; this.opts.algorithm = customOptions.algorithm && isValidSpriteLayout(customOptions.algorithm) @@ -52,6 +55,10 @@ const pluginOptions = { customOptions.spritePath || '' ); + this.opts.outputStylesheetPath = customOptions.outputStylesheetPath + ? path.resolve(process.cwd(), customOptions.outputStylesheetPath) + : undefined; + return this.opts; }, diff --git a/lib/update-references.js b/lib/update-references.js index 7627286..af60254 100644 --- a/lib/update-references.js +++ b/lib/update-references.js @@ -114,7 +114,10 @@ function updateReferences(images, sprites, css) { // Generate the correct reference to the sprite. image.spriteRef = path - .relative(image.stylesheetPath, image.spritePath) + .relative( + opts.outputStylesheetPath || image.stylesheetPath, + image.spritePath + ) .split(path.sep) .join('/');