gulp-sprity
A gulp plugin to convert a set of images into a spritesheet.
Usage
Firstly, install gulp-sprity
as a development dependency:
npm install gulp-sprity --save-dev
Then, add it into your gulpfile.js
:
convert by default mode, background image url with end of #sprite:
const cleanCSS = ;const gulpif = ;const sprity = ;const path = ; { return { return path === '.' + type; };} gulp ;
input
/*foo.css*/
output
/*foo.css*/
** imagePixelRatio **
gulp ;
input
/*foo.css*/
output
/*foo.css*/
spritePrefix usage:
const cleanCSS = ;const gulpif = ;const sprity = ;const path = ; { return { return path === '.' + type; };} gulp ;
the same as:
output like:
/*foo.css*/
Parameters
keepInRoot
Type: bool
default undefined
To mark whether put the image files into the same directory of image file path. For example, one file path is /Users/demo/src/images/dir1/img1.png. Another one is /Users/demo/src/images/dir2/img2.png. Then the spriter will be saved in /Users/demo/src/images.
spriteMark
Type: String
default #sprite
To mark which image should be merged into a spritesheet.
spritePrefix
Type: String
default: undefined
To add the prefix directory path of spritesheet and save the sprited image to the prefix directory.
imagePixelRatio
Type: Integer
default undefined
To scale the background-size and background-position of the spriter for HD images.
spriteFileNameReplacer
Type: Function
default: undefined
Parameters:
- fileName: the file name of the original css file with no extname.
To change the file name of the sprited image.
backgroundUrlHandler
Type: Function
default undefined
Parameters:
- imgFilePath: origin saved path of spritesheet
- filePath: the file path of original file
To handle the url of background-image, output what you want to insert into css file.
spritePathReplacer
Type: Function
default undefined
Parameters:
- dir: backgroung image url which will be injected into css file
- imgFilePath: origin saved path of spritesheet
- filePath: the file path of original file
To replace the path of a spritesheet where you want to save the spritesheet.