在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gobwas/gulp-sprite-generator开源软件地址(OpenSource Url):https://github.com/gobwas/gulp-sprite-generator开源编程语言(OpenSource Language):JavaScript 95.2%开源软件介绍(OpenSource Introduction):gulp-sprite-generator
Plugin that generate sprites from your stylesheets (using spritesmith) and then updates image references. Getting startedIf you haven't used gulp before, be sure to check out the Getting Started guide. Install with npm
OverviewSprite generator is a gulp task, which accepts options object and returns two streams for style and image piping. Here quick example of simple way usage: var gulp = require('gulp');
var sprite = require('gulp-sprite-generator');
gulp.task('sprites', function() {
var spriteOutput;
spriteOutput = gulp.src("./src/css/*.css")
.pipe(sprite({
baseUrl: "./src/image",
spriteSheetName: "sprite.png",
spriteSheetPath: "/dist/image"
}));
spriteOutput.css.pipe(gulp.dest("./dist/css"));
spriteOutput.img.pipe(gulp.dest("./dist/image"));
}); Of course you may need to have more flexible configuration for spriting. And this plugin can give you something more! OptionsSprite generator options is an object, that mix spritesmith options and plugin specific options. Spritesmith parameters (all is optional):
More detailed explanation you can find on the official page of spritesmith. Plugin options are:
More detailed explanation is below. options.spriteSheetNameType: The one and last necessary parameter. Defines which base will have the name of the output sprite. Base means that if you will group your sprites by some criteria, name will change. options.spriteSheetPathType: Can define relative path of references in the output stylesheet. options.styleSheetNameType: Defines the name of the output stylesheet. options.baseUrlType: Defines where to find relatively defined image references in the input stylesheet. options.retinaType: Defines whether or not to search for retina mark in the filename. If options.filterType: Defines which filters apply to images found in the input stylesheet. Each filer called with image object, explained below. Each filter must return options.groupByType: Defines logic of how to group images found in the input stylesheet. Each grouper called with image object, explained below. Each filter must return options.accumulateType: Tells sprite-generator to accumulate images from multiple stylesheets. This mean, that images, found in stylesheet
options.verboseType: Filtering and groupingSprite generator can filter and group images from the input stylesheet. Built in filters:
Built in groupers:
You can of course define your own filters or groupers. It will all based on main argument - the image object. The Image objectEvery filter or grouper is called with
Doc block meta propertiesYou can also define some properties for the filters and groupers in doc block via this syntax:
Example: .my_class {
background-image: url("/images/my.png"); /* @meta {"sprite": {"skip": true}} */
} Important! Only object in Flexible examplevar gulp = require('gulp'),
sprite = require('gulp-sprite-generator'),
Q = require('q'),
sizeOf = require('image-size');
gulp.task('sprites', function() {
var spriteOutput;
spriteOutput = gulp.src("./src/css/*.css")
.pipe(sprite({
baseUrl: "./",
spriteSheetName: "sprite.png",
spriteSheetPath: "/dist/image",
styleSheetName: "stylesheet.css",
filter: [
// this is a copy of built in filter of meta skip
// do not forget to set it up in your stylesheets using doc block /* */
function(image) {
return !image.meta.skip;
}
],
groupBy: [
// group images by width
// useful when building background repeatable sprites
function(image) {
var deferred = Q.defer();
sizeOf(image.path, function(err, size) {
deferred.resolve(size.width.toString());
});
return deferred.promise;
}
]
});
spriteOutput.css.pipe(gulp.dest("./dist/css"));
spriteOutput.img.pipe(gulp.dest("./dist/image"));
}); LicenseMIT © Sergey Kamardin |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论