2createStudio / postcss-sprites

Generate sprites from stylesheets.
MIT License
413 stars 50 forks source link

Question. How to avoid sprites overwriting #43

Closed NXTaar closed 8 years ago

NXTaar commented 8 years ago

Here is my file structure structure

I'm using webpack

sidebar/icons.scss

.actionExit {
    background: url("images/exit.png");
    size: 26px 20px;
}

.actionMenu {
    background: url("images/menu.png");
    size: 19px 13px;
}

.actionStat {
    background: url("images/graph.png");
    size: 24px 20px;
}

//and so on

dashboard-notifications-area/styles.scss

.bubble {
    position: relative;
    top: 20px;
    left: 20px;
    size: 108px;
    background: url("bubble.png");
    color: white;
    text-align: center;
}

plugin configuration

sprites( {
            spritesmith: { padding: 10 },
            spritePath: './dist/assets'
        })

When it compiles the output is like

postcss-sprites: 0 spritesheet generated.
postcss-sprites: 0 spritesheet generated.
postcss-sprites: 0 spritesheet generated.
postcss-sprites: 1 spritesheet generated.
postcss-sprites: 1 spritesheet generated.

It generates two different spritesheets for each .scss file, and obviously the second, overrides the first one, and i get in the sprite.png only the sprite for bubble.png

How to tell the plugin to merge all of it to one file, and don't create a new sprite.png per each .scss file

vvasilev- commented 8 years ago

You need a single entry point so just combine your CSS files and pass them to the plugin.

NXTaar commented 8 years ago

Unfortunately i can't do that, because my components are independent, and they don't have a single entry point

vvasilev- commented 8 years ago

I think that there is no way to get working this, because webpack will process your files independently.

NXTaar commented 8 years ago

Ok, thanks for help. Will try something other way

YingshanDeng commented 8 years ago

@NXTaar I have the same problem like you. https://github.com/YingshanDeng/polymer-generate-spritesheet And now do you have a solution ?

vvasilev- commented 8 years ago

@YingshanDeng, You can use groupBy option to create a separate spritesheet per component.

YingshanDeng commented 8 years ago

Hello @vvasilev- what i need is generate all the component into one spritesheet. and it is my demo: https://github.com/YingshanDeng/polymer-generate-spritesheet but has some problem.

Martin-Mo commented 5 years ago

To combine all images into one sprite.png, you could try the following way:

1.Creating a mixin named "_sprites.scss" and writing all sprite related classes here

2.Extending the css classes mentioned above in your component's style file.