Installations
npm install webpack-spritesmith-handlebars-helpers
Releases
Unable to fetch releases
Developer
machengda
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
7.2.0
NPM Version
4.4.4
Statistics
3 Stars
64 Commits
2 Watching
2 Branches
Updated on 21 Apr 2017
Languages
JavaScript (99.27%)
CSS (0.73%)
Total Downloads
Cumulative downloads
Total Downloads
92,326
Last day
61.5%
63
Compared to previous day
Last week
10.6%
260
Compared to previous week
Last month
33.1%
1,250
Compared to previous month
Last year
11.9%
16,322
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Webpack plugin that converts set of images into a spritesheet and SASS/LESS/Stylus mixins, using spritesmith and spritesheet-templates
All ideas are shamelessly taken from gulp.spritesmith.
Example
Let's say you have following folder structure
/
|-src
| |-ico
| | |-new.png
| | |-open.png
| | |-save.png
| | ...
| |-style.styl
| ...
|-webpack.config.js
Then you need to instantiate plugin in webpack config like this:
1 2//webpack.config.js 3var path = require('path'); 4 5var SpritesmithPlugin = require('webpack-spritesmith'); 6 7module.exports = { 8 // ... 9 module: { 10 loaders: [ 11 {test: /\.styl$/, loaders: [ 12 'style-loader', 13 'css-loader', 14 'stylus-loader' 15 ]}, 16 {test: /\.png$/, loaders: [ 17 'file-loader?name=i/[hash].[ext]' 18 ]} 19 ] 20 }, 21 resolve: { 22 //webpack 1: 23 modulesDirectories: ["node_modules", "spritesmith-generated"], 24 //webpack 2: 25 modules: ["node_modules", "spritesmith-generated"] 26 }, 27 plugins: [ 28 new SpritesmithPlugin({ 29 src: { 30 cwd: path.resolve(__dirname, 'src/ico'), 31 glob: '*.png' 32 }, 33 target: { 34 image: path.resolve(__dirname, 'src/spritesmith-generated/sprite.png'), 35 css: path.resolve(__dirname, 'src/spritesmith-generated/sprite.styl') 36 }, 37 apiOptions: { 38 cssImageRef: "~sprite.png" 39 } 40 }) 41 ] 42 // ... 43}; 44 45
And then just use it
1 2//style.styl 3@import '~sprite.styl' 4 5.close-button 6 sprite($close) 7.open-button 8 sprite($open) 9
There are few things to notice in config
- file-loader used for generated image
resolve
contains location of where generated image is- cssImageRef is specified as '~sprite.png'
So the way generated image is accessed from generated API at the moment has to be specified manually.
Config
-
src
- used to build list of source imagescwd
should be the closest common directory for all source images;glob
well... it is a glob
cwd
andglob
both will be passed directly to glob (and gaze in watch mode), then resulting list of files will be used as list of source images -
target
- generated filesimage
- target image filename. Can be interpolated with loader-utils. Though I would recommend to use file-loader for interpolation.css
- can be one of the following-
"full/path/to/spritesheet/api"
- for examplepath.resolve(__dirname, 'src/spritesmith-generated/sprite.styl')
-
["full/path/to/spritesheet/api1", "full/path/to/spritesheet/api2"]
, -
["full/path/to/spritesheet/api1", ["full/path/to/spritesheet/api2", spritesmithTemplatesOptions]]
spritesmithTemplatesOptions - is the second argument herefor example
1 ... 2 css: [ 3 path.resolve(__dirname, 'src/spritesmith-generated/sprite.styl'), 4 [path.resolve(__dirname, 'src/spritesmith-generated/sprite.json'), { 5 format: 'json_texture' 6 }] 7 ]
-
-
apiOptions
- optionalgenerateSpriteName
- function. Takes full path to source image file and expected to return name by which it will be referenced in API. Return value will be used assprite.name
for spritesheet-templates. Default behaviour is to use filename (without dirname and extension)cssImageRef
- path by which generated image will be referenced in API. If target.image is interpolated, cssImageRef should be interpolated the same way too.
-
spritesmithOptions
- optional. Options for spritesmith -
retina
- optional, when specified, uses retina capabilities of spritesheet-templates. Can be either suffix string (like '@2x') or object consisting of three fields:classifier
-Function
that allows to say which source is for retina spritesheet and which is not. Will be called with full path to source file, and should return an object of this format -1 2 { 3 type: String, // determines which kind of source is this. Can contain one of two values: 'retina' and 'normal' 4 normalName: String, //full path to corresponding normal source image 5 retinaName: String, //full path to corresponding retina source image 6 }
targetImage
- full path to generated retina imagecssImageRef
- path by which generated image will be referenced in API
When used as suffix string it applies to source files, filename for retina spritesheet image and cssImageRef
apiOptions.generateSpriteName
will be applied tonormalName
returned by retina.classifier -
customTemplates
- optional. Object with keys and values corresponding to format names and template descriptions respectively. Template description can be either apath/to/handlebars/template/file
or template function -
cssHandlebarsHelpers
- optional. Container for helpers to register to handlebars for our template Each- key-value pair is the name of a handlebars helper corresponding to its function
- For example, {half: function (num) { return num/2; } will add a handlebars helper that halves numbers
You can use templates registered here as
format
in "target.css"For example you can write something like this
1 2//webpack.config.js 3var templateFunction = function (data) { 4 var shared = '.ico { background-image: url(I) }' 5 .replace('I', data.sprites[0].image); 6 7 var perSprite = data.sprites.map(function (sprite) { 8 return '.ico-N { width: Wpx; height: Hpx; background-position: Xpx Ypx; }' 9 .replace('N', sprite.name) 10 .replace('W', sprite.width) 11 .replace('H', sprite.height) 12 .replace('X', sprite.offset_x) 13 .replace('Y', sprite.offset_y); 14 }).join('\n'); 15 16 return shared + '\n' + perSprite; 17}); 18 19module.exports = { 20 ... 21 plugins: [ 22 new SpritesmithPlugin({ 23 target: { 24 ... 25 css: [ 26 [path.resolve(__dirname, 'src/spritesmith-generated/sprite-1.css'), { 27 format: 'function_based_template' 28 }], 29 [path.resolve(__dirname, 'src/spritesmith-generated/sprite-2.css'), { 30 format: 'handlebars_based_template' 31 }] 32 ] 33 }, 34 customTemplates: { 35 'function_based_template': templateFunction, 36 'handlebars_based_template': path.resolve(__dirname, '../my_handlebars_template.handlebars') 37 }, 38 cssHandlebarsHelpers: { 39 "px2Rem": function(px) { 40 ... 41 } 42 } 43 ... 44 }) 45 ] 46} 47
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to webpack-spritesmith-handlebars-helpers
@budibase/handlebars-helpers
More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
handlebars-loader
handlebars loader module for webpack
handlebars-helpers
More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
just-handlebars-helpers
A lightweight package with common helpers for Handlebars