
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sprite-smith-loader
Advanced tools
:rocket: 中文文档点这里
Sprite Smith loader is a tool for automatically generating CSS Sprites. You can use it in webpack. It will find all the_ sprite.png End picture and auto generate CSS Sprites and modify the corresponding CSS code.
supports CSS、SASS、LESS.
The picture should be in PNG format (do not directly change the picture suffix to PNG)
To begin, you'll need to install sprite-smith-loader:
npm install --save-dev sprite-smith-loader remove-file-webpack-plugin
Then add the plugin to your webpack config. And don't forget to add the file-loader or url-loader.
For example:
webpack.config.js
// add remove-file-webpack-plugin to clean sprites folders
const RemoveFileWebpackPlugin = require('remove-file-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
outputPath: 'images',
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader','sprite-smith-loader'],
},
],
},
plugins: [
new RemoveFileWebpackPlugin({
dirNames:["sprites"]
})
],
};
with SASS
const RemoveFileWebpackPlugin = require('remove-file-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
outputPath: 'images',
},
},
{
test: /\.(sass|scss|css)/,
use: ['style-loader', 'css-loader','sprite-smith-loader',"sass-loader"],
}
],
},
plugins: [
new RemoveFileWebpackPlugin({
dirNames:["sprites"]
})
],
};
Change the picture name to_ sprite.png End and reference it in CSS
.my_bg_1{
height: 100px;
width: 100px;
background: url('./demo1_sprite.png') 0px 0px;
background-size: 100px 100px;
}
.my_bg_2{
height: 100px;
width: 100px;
background: url('./demo2_sprite.png') -20px -20px;
background-size: 150px 150px;
}
After the CSS Sprites is generated, the loader will modify the background attribute in the CSS. In order to accurately calculate the converted background attribute, please follow the following specifications:
| Css attribute name | isRequired | Description |
|---|---|---|
| height | true | Unit: PX |
| width | true | Unit: PX |
| background-size | true | Unit: PX |
| background | true | Include image,position,repeat |
| background-image | true | Included in background,picture name with _ sprite.png ending |
| background-position | false | Included in background,format of value PX PX |
| background-repeat | false | Included in background,must be no-repeat |
If you have any questions, please create an issue on GitHub.
FAQs
css sprites loader for webpack
We found that sprite-smith-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.