11# PostCSS Sprites
22[ PostCSS] ( https://github.com/postcss/postcss ) plugin that generate sprites from your stylesheets and then updates image references.
33
4- ## Todo
5-
6- - [ ] Tests
7- - [ ] Publish as NPM module
8-
94## Install
105
116```
@@ -25,12 +20,47 @@ var opts = {
2520};
2621
2722postcss (sprites (opts))
28- .process (css, { from: ' src/app.css' , to: ' app.css' })
23+ .process (css, { from: ' ./ src/app.css' , to: ' ./dist/ app.css' })
2924 .then (function (result ) {
30- fs .writeFileSync (' app.css' , result .css );
25+ fs .writeFileSync (' ./dist/ app.css' , result .css );
3126 });
3227```
3328
29+ #### Input
30+ ``` css
31+ .comment { background : #fff url (images/sprite/ico-comment.png ) no-repeat 0 0 ; }
32+ .bubble { background : url (images/sprite/ico-bubble.png ) no-repeat 0 0 ; }
33+
34+ .arrows { background : url (images/sprite/arrows@2x.png ) no-repeat 0 0 ; }
35+ .logo { background : url (images/sprite/logo@2x.png ) no-repeat 0 0 ; }
36+ ```
37+
38+ #### Output
39+ ``` css
40+ .comment { background-image : url (images/sprite.png ); background-position : 0 0 ; background-color : #fff ; }
41+ .bubble { background-image : url (images/sprite.png ); background-position : 0 -50px ; }
42+
43+ .arrows { background-image : url (images/sprite.@2x.png ); background-position : 0 0 ; background-size : 100px 100px ; }
44+ .logo { background-image : url (images/sprite.@2x.png ); background-position : 0 -50px ; background-size : 100px 100px ; }
45+ ```
46+
47+ #### Output - external
48+ ``` css
49+ .comment ,
50+ .bubble { background-image : url (images/sprite.png ); background : no-repeat ; }
51+
52+ .comment { background-position : 0 0 ; width : 50px ; height : 50px ; }
53+ .bubble { background-position : 0 -50px ; width : 50px ; height : 50px ; }
54+
55+ @media (-webkit-min-device-pixel-ratio : 2 ), (min-resolution : 192dpi ) {
56+ .arrows ,
57+ .logo { background-image : url (images/sprite.@2x.png ); background : no-repeat ; background-size : 100px 100px ; }
58+
59+ .arrows { background-position : 0 0 ; width : 50px ; height : 50px ; }
60+ .logo { background-position : 0 -50px ; width : 50px ; height : 50px ; }
61+ }
62+ ```
63+
3464## Options (plugin)
3565
3666#### spriteName
@@ -209,9 +239,9 @@ var opts = {
209239};
210240
211241postcss (sprites (opts))
212- .process (css, { from: ' src/app.css' , to: ' app.css' })
242+ .process (css, { from: ' ./ src/app.css' , to: ' ./dist/ app.css' })
213243 .then (function (result ) {
214- fs .writeFileSync (' app.css' , result .css );
244+ fs .writeFileSync (' ./dist/ app.css' , result .css );
215245 });
216246```
217247
0 commit comments