Skip to content

Commit

Permalink
feat: added outputStylesheetPath option (#203)
Browse files Browse the repository at this point in the history
* feat: added outputStylesheetPath option

* fix: accept 0 as padding value instead of using default padding
  • Loading branch information
kenfoo authored Jul 18, 2020
1 parent 3e3ac17 commit 676e8ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion lib/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,6 +55,10 @@ const pluginOptions = {
customOptions.spritePath || ''
);

this.opts.outputStylesheetPath = customOptions.outputStylesheetPath
? path.resolve(process.cwd(), customOptions.outputStylesheetPath)
: undefined;

return this.opts;
},

Expand Down
5 changes: 4 additions & 1 deletion lib/update-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');

Expand Down

0 comments on commit 676e8ff

Please sign in to comment.