Skip to content

A webpack sprite loader that generates spritesheets based on your stylesheets.

Notifications You must be signed in to change notification settings

Chorer/Webpack-SpriteLoader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webpack-sprite-loader

A webpack sprite loader that generates spritesheets based on your stylesheets.

Usage

install the loader:

npm i webpack-sprite-loader -D

configure the webpack:

const webpack-sprite-loader = require('webpack-sprite-loader')
module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          'webpack-sprite-loader'
        ]
      }
    ]
  }
}

write css like this:

div.bgc1 {
  /* add '?__sprite' flag after each image url */
  background: url('./src/test1.png?__sprite')
}
div.bgc2 {
  background: url('./src/test2.png?__sprite')
}

What you get finally is:

div.bgc1 {
  background: url('./sprite.png');
  background-position: 0 -895px;
}
div.bgc2 {
  background: url('./sprite.png');
  background-position: 0 0;
}

About

A webpack sprite loader that generates spritesheets based on your stylesheets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published