All Projects → 2createStudio → Postcss Sprites

2createStudio / Postcss Sprites

Licence: mit
Generate sprites from stylesheets.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Postcss Sprites

Teenyicons
Tiny minimal 1px icons designed to fit in the smallest places.
Stars: ✭ 1,631 (+305.72%)
Mutual labels:  svg-sprites, svg, sprites
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (-94.28%)
Mutual labels:  postcss, postcss-plugin
postcss-windicss
PostCSS integrations for Windi CSS
Stars: ✭ 33 (-91.79%)
Mutual labels:  postcss, postcss-plugin
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (-89.8%)
Mutual labels:  postcss, postcss-plugin
Postcss Responsive Type
Automagical responsive typography, built on PostCSS
Stars: ✭ 363 (-9.7%)
Mutual labels:  postcss, postcss-plugin
postcss-purgecss
PostCSS plugin for purgecss
Stars: ✭ 92 (-77.11%)
Mutual labels:  postcss, postcss-plugin
postcss-lazyimagecss
A PostCSS plugin that generates images's CSS width & height properties automatically.
Stars: ✭ 38 (-90.55%)
Mutual labels:  postcss, postcss-plugin
postcss-styl
PostCSS parser plugin for converting Stylus syntax to PostCSS AST.
Stars: ✭ 15 (-96.27%)
Mutual labels:  postcss, postcss-plugin
postcss-typed-css-classes
PostCSS plugin that generates typed entities from CSS classes for chosen programming language.
Stars: ✭ 12 (-97.01%)
Mutual labels:  postcss, postcss-plugin
postcss-aspect-ratio
A PostCSS plugin to fix an element's dimensions to an aspect ratio.
Stars: ✭ 38 (-90.55%)
Mutual labels:  postcss, postcss-plugin
postcss-sort-media-queries
PostCSS plugin for combine and sort CSS media queries with mobile first or desktop first methods.
Stars: ✭ 118 (-70.65%)
Mutual labels:  postcss, postcss-plugin
postcss
No description or website provided.
Stars: ✭ 59 (-85.32%)
Mutual labels:  postcss, postcss-plugin
postcss-rename
Replace class names based on a customizable renaming scheme.
Stars: ✭ 77 (-80.85%)
Mutual labels:  postcss, postcss-plugin
postcss-prefixwrap
A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
Stars: ✭ 54 (-86.57%)
Mutual labels:  postcss, postcss-plugin
postcss-critical-css
PostCSS plugin to define and output critical CSS using custom atRules, and/or custom CSS properties. Critical CSS may be output to one or more files, as defined within the plugin options or within the CSS.
Stars: ✭ 84 (-79.1%)
Mutual labels:  postcss, postcss-plugin
postcss-font-pack
PostCSS plugin to simplify font declarations by validating only configured font packs are used and adding fallbacks.
Stars: ✭ 18 (-95.52%)
Mutual labels:  postcss, postcss-plugin
postcss-momentum-scrolling
PostCSS plugin add 'momentum' style scrolling behavior (-webkit-overflow-scrolling: touch) for elements with overflow (scroll, auto) on iOS
Stars: ✭ 69 (-82.84%)
Mutual labels:  postcss, postcss-plugin
postcss-import-url
PostCSS plugin inlines remote files.
Stars: ✭ 47 (-88.31%)
Mutual labels:  postcss, postcss-plugin
postcss-inline-media
Media queries shortcut, built on PostCSS, example: font-size: 20px @1200 18px @480 16px;
Stars: ✭ 47 (-88.31%)
Mutual labels:  postcss, postcss-plugin
postcss-define-function
PostCSS plugin for Sass-like function directive
Stars: ✭ 25 (-93.78%)
Mutual labels:  postcss, postcss-plugin

postcss-sprites Build Status npm version

PostCSS plugin that generates spritesheets from your stylesheets.

/* Input */
.comment { background: url(images/sprite/ico-comment.png) no-repeat 0 0; }
.bubble { background: url(images/sprite/ico-bubble.png) no-repeat 0 0; }

/* ---------------- */

/* Output */
.comment { background-image: url(images/sprite.png); background-position: 0 0; }
.bubble { background-image: url(images/sprite.png); background-position: 0 -50px; }

Usage

var fs = require('fs');
var postcss = require('postcss');
var sprites = require('postcss-sprites');

var css = fs.readFileSync('./css/style.css', 'utf8');
var opts = {
	stylesheetPath: './dist',
	spritePath: './dist/images/'
};

postcss([sprites(opts)])
	.process(css, {
		from: './css/style.css',
		to: './dist/style.css'
	})
	.then(function(result) {
		fs.writeFileSync('./dist/style.css', result.css);
	});

See PostCSS docs for examples for your environment.


Options

stylesheetPath

Relative path to the folder that will keep your output stylesheet(s). If it's null the path of CSS file will be used.

  • Default: null
  • Required: false
spritePath

Relative path to the folder that will keep your output spritesheet(s).

  • Default: ./
  • Required: true
basePath

Your base path that will be used for images with absolute CSS urls.

  • Default: ./
  • Required: false
relativeTo

Indicates whether the url should be relative against current CSS context or original CSS stylesheet file.

  • Default: file
  • Required: false
  • Options: file|rule
filterBy

Defines filter functions that will manipulate the list of images founded in your stylesheet(s).

  • Default: []
  • Required: false
  • Options: Function|Function[]

Every function must return a Promise which should be resolved or rejected.

Built-in filters:

  • based on fs.stat and used to remove non exisiting images
groupBy

Defines group functions that will manipulate the list of images founded in your stylesheet(s).

  • Default: []
  • Required: false
  • Options: Function|Function[]

Every function must return a Promise which should be resolved with a string or rejected.

Built-in filters:

  • based on @2x naming convention
retina

Defines whether or not to search for retina mark in the filename.

  • Default: false
  • Required: false
hooks

Defines whether or not to search for retina mark in the filename.

  • Default: {}
  • Required: false
hooks.onSaveSpritesheet

Hook that allows to rewrite the data of produced spritesheet.

If returned value is string, it is used as filepath value, and if returned value is object, it is used as value which will be merged with current spritesheet data.

Returned value can also be Promise which should return either string or object.

  • Default: null
  • Required: false
hooks.onUpdateRule

Hook that allows to rewrite the CSS output for an image.

  • Default: null
  • Required: false
spritesmith

A spritesmith configuration.

  • Default: {}
  • Required: false
spritesmith.engine

The engine.

  • Default: pixelsmith
  • Required: false
spritesmith.algorithm

The algorithm.

  • Default: binary-tree
  • Required: false
spritesmith.padding

The space between images in spritesheet.

  • Default: 0
  • Required: false
spritesmith.engineOpts

The configuration of the engine.

  • Default: {}
  • Required: false
spritesmith.exportOpts

The export options of the engine.

  • Default: {}
  • Required: false
svgsprite

A svg-sprite configuration.

verbose

Prints the plugin output to the console.

  • Default: false
  • Required: false

The Image

Every filter or group function will be called with an Image object.

styleFilePath

An absolute path to the stylesheet - /Path/to/your/source/stylesheet.css

path

An absolute path to the image - /Path/to/your/image.png

originalUrl

The url found in your stylesheet including the query params - ../image.png?v1

url

A normalized version of the original url - ../image.png

ratio

The retina ratio of your image - 2

retina

Indicates whenever your image is retina - true

groups

The groups associated with the image - ['shapes', '@2x']

token

The string used as reference in your stylesheet - /* @replace|image.png */

coords

The position & dimensions of image in generated spritesheet - { width: 20, height: 20, x: 0, y: 0 }

spritePath

A relative path to the generated spritesheet - dist/sprite.png

spriteUrl

A CSS url to the generated spritesheet - sprite.png

spriteWidth

The total width of the spritesheet - 200

spriteHeight

The total height of the spritesheet - 400


Advanced


Contributing

Pull requests are welcome.

$ git clone [email protected]:2createStudio/postcss-sprites.git
$ npm install
$ npm run watch
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].