Gathering detailed insights and metrics for webpack-spritesmith-handlebars-helpers
Gathering detailed insights and metrics for webpack-spritesmith-handlebars-helpers
Gathering detailed insights and metrics for webpack-spritesmith-handlebars-helpers
Gathering detailed insights and metrics for 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
npm install webpack-spritesmith-handlebars-helpers
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
64 Commits
2 Watching
2 Branches
Updated on 21 Apr 2017
JavaScript (99.27%)
CSS (0.73%)
Cumulative downloads
Total Downloads
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
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.
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
resolve
contains location of where generated image isSo the way generated image is accessed from generated API at the moment has to be specified manually.
src
- used to build list of source images
cwd
should be the closest common directory for all source images;glob
well... it is a globcwd
and glob
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 files
image
- 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 example path.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 here
for 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
- optional
generateSpriteName
- 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 as sprite.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 APIWhen used as suffix string it applies to source files, filename for retina spritesheet image and cssImageRef
apiOptions.generateSpriteName
will be applied to normalName
returned by retina.classifier
customTemplates
- optional. Object with keys and values corresponding to format names and template descriptions respectively.
Template description can be either a path/to/handlebars/template/file
or template function
cssHandlebarsHelpers
- optional. Container for helpers to register to handlebars for our template Each
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
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
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
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 More