• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Otouto/gulp-spritesmith: gulp plugin for sprite generation

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Otouto/gulp-spritesmith

开源软件地址(OpenSource Url):

https://github.com/Otouto/gulp-spritesmith

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-spritesmith

NPM version Dependency Status

Gulp plugin for sprite generation, based on spritesmith.

Usage

First, install gulp-spritesmith as a development dependency:

npm i -D gulp-spritesmith

Then, add it to your gulpfile.js:

var spritesmith = require("gulp-spritesmith");
var gulpif = require("gulp-if");

gulp.task('sprites', function () {
    return  gulp.src('./src/**/png/*.png')
                .pipe(tasks.spritesmith({
                    imgName: 'sprite.png',
                    styleName: 'sprite.css',
                    imgPath: '../img/sprite.png'
                }))
                .pipe(gulpif('*.png', gulp.dest('./dist/img/')))
                .pipe(gulpif('*.css', gulp.dest('./dist/css/')));
});

If you need few grouped sprites, you should specify folder name to group by. Lets say you have following app structure, with several skins:

  • /Module1
    • ...
    • /skin
      • /basic
        • /png
      • /green
        • /png
      • /dark
        • /png
      • /light
        • /png
  • ...
  • /ModuleN
    • ...
    • /skin
      • /basic
        • /png
      • /green
      • /dark
        • /png
      • /light

Then just set skin for groupBy param:

gulp.task('sprites', function () {
    return  gulp.src('./src/**/png/*.png')
                .pipe(tasks.spritesmith({
                    imgName: 'sprite.png',
                    styleName: 'sprite.css',
                    imgPath: '../img/sprite.png',
                    groupBy: 'skin'
                }))
                .pipe(gulpif('*.png', gulp.dest('./dist/img/')))
                .pipe(gulpif('*.css', gulp.dest('./dist/css/')));
});

and you`ll get 4 sprites: sprite.basic.png, sprite.green.png, sprite.dark.png, sprite.light.png. And the same for css.

API

spritesmith(options)

options.imgName

Type: String Default: ``

Set name for sprite img file.

options.styleName

Type: String Default: ``

Set name for sprite styles file.

options.imgPath

Type: String Default: ``

Set relative path to sprite img, which will be used in styles file.

options.styleTemplate

Type: String Default: ``

Path to mustache tmpl file, to format output styles file.

Set relative path to sprite img, which will be used in styles file.

options.groupBy

Type: String Default: ``

Set if you want to get grouped sprites.

options.algorithm

Type: String Default: binary-tree

Set packing algorithm, top-down/left-right/diagonal/alt-diagonal/binary-tree are available.

options.padding

Type: Number Default: 1

Set padding in pixels to use between images

Changelog

0.0.2 - Dont save sprite files inside task anymore.

0.0.1 - initial version

License

MIT License




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
AngularClass · GitHub发布时间:2022-06-21
下一篇:
AngularClass/ES6-build-tools: Tutorial + exercises on setting up an ES6 environm ...发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap