@@ -36,8 +36,7 @@ var TEMPLATES = {
3636 * @type {Object }
3737 */
3838var defaults = {
39- baseUrl : './' ,
40- externalStyle : 'sprite.css' ,
39+ externalStyle : false ,
4140 spritePath : null ,
4241 spriteName : 'sprite.png' ,
4342 filterBy : [ ] ,
@@ -175,12 +174,8 @@ function getImages(css, opts) {
175174 image . ratio = getRetinaRatio ( image . url ) ;
176175 }
177176
178- if ( image . url . charAt ( 0 ) === '/' ) {
179- // The path is relative
180- image . path = path . resolve ( opts . baseUrl + image . url ) ;
181- } else {
182- image . path = path . resolve ( styleFilePath . substring ( 0 , styleFilePath . lastIndexOf ( path . sep ) ) , image . url ) ;
183- }
177+ // Get the path to the image.
178+ image . path = path . resolve ( styleFilePath . substring ( 0 , styleFilePath . lastIndexOf ( path . sep ) ) , image . url ) ;
184179
185180 // Extract the selector for usage in
186181 // the external stylesheet.
@@ -454,6 +449,10 @@ function updateReferences(images, opts, sprites, css) {
454449 if ( isToken ( comment ) ) {
455450 image = lodash . find ( images , { url : comment . text } ) ;
456451
452+ // Fix path to the sprite
453+ image . spriteRef = path . relative ( path . dirname ( css . source . input . file ) , image . spritePath ) ;
454+ image . spriteRef = path . posix . normalize ( image . spriteRef ) ;
455+
457456 if ( image ) {
458457 backgroundImage = postcss . decl ( {
459458 prop : 'background-image' ,
@@ -756,7 +755,7 @@ function isToken(comment) {
756755 * @return {String }
757756 */
758757function getBackgroundImageUrl ( image ) {
759- var template = lodash . template ( 'url(<%= image.spritePath %>)' ) ;
758+ var template = lodash . template ( 'url(<%= image.spriteRef %>)' ) ;
760759
761760 return template ( { image : image } ) ;
762761}
0 commit comments