postcss-auto-sprite

1.0.5 • Public • Published

Postcss Auto Sprite

PostCSS Auto Sprite plugin that generates css and sprites which grouped by directory from your stylesheets

Installation

$ npm install postcss-auto-sprite --save-dev

Usage

Use gulp

const gulp = require("gulp");
const postcss = require("gulp-postcss");
const sprite = require("postcss-auto-sprite");
gulp.task("css", () => {
  return gulp
    .src("*.css")
    .pipe(
      postcss([
        sprite({
          imgPath: __dirname + "/img/",
          sliceDir: "slice",
          spriteDir: "sprite",
          spriteDisplay: "../img/sprite",
          revision: "query", // 'filename' or 'query'
          unit: "px", // 'px' or 'rem'
          spritesmithOptions: {
            padding: 10
          },
          revision: true
        })
      ])
    )
    .pipe(gulp.dest("./dist/css"));
});

Before:

.icon1{
  background-image: url('../img/slice/dir1/icon_1.png');
}
.icon2{
  background-image: url('../img/slice/dir1/icon_2.png');
}
.icon3{
  background-image: url('../img/slice/dir2/icon_3.png');
}
.icon4{
  background-image: url('../img/slice/dir2/icon_4.png');
}

After:

.icon1{
  width: 20px;
  height: 20px;
  background-image: url('../img/sprite/dir1.png');
  background-position: 0px 0px;
  background-size: 50px auto
}
.icon2{
  width: 20px;
  height: 20px;
  background-image: url('../img/sprite/dir1.png');
  background-position: -30px 0px;
  background-size: 50px auto
}
.icon3{
  width: 20px;
  height: 20px;
  background-image: url('../img/sprite/dir2.png');
  background-position: 0px 0px;
  background-size: 50px auto
}
.icon4{
  width: 20px;
  height: 20px;
  background-image: url('../img/sprite/dir2.png');
  background-position: -30px 0px;
  background-size: 50px auto
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.51latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.51
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i postcss-auto-sprite

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

74 kB

Total Files

36

Last publish

Collaborators

  • rpsh