Skip to content

Commit 61d9f95

Browse files
committed
1.0.3
1 parent ed19421 commit 61d9f95

File tree

6 files changed

+272
-144
lines changed

6 files changed

+272
-144
lines changed

README.CN.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
![image](https://img.shields.io/badge/license-MIT-green)
55
![image](https://img.shields.io/badge/webpack-%5E4.0.0-blue)
66
## 介绍
7-
sprite-smith-loader是一款自动生成雪碧图工具,你可以在webpack中使用它,它会自动生成雪碧图并修改相应的css代码
7+
sprite-smith-loader是一款自动生成雪碧图工具,你可以在webpack中使用它,它会遍历css中以_sprite.png结尾的图片并自动生成雪碧图,然后修改相应的css代码
88

99
支持**CSS****SASS****LESS**
10+
11+
图片应为png格式(不要直接将图片后缀改为png)。
1012
## 安装
1113
下载sprite-smith-loader
1214

@@ -62,7 +64,7 @@ module.exports = {
6264

6365

6466
## 使用
65-
修改你的 CSS/SCSS/SASS/LESS 文件
67+
修改图片名以 **_sprite.png** 结尾,并在css中引入它
6668

6769
```
6870
.my_bg_1{
@@ -79,7 +81,7 @@ module.exports = {
7981
background-size: 150px 150px;
8082
}
8183
```
82-
雪碧图生成后,loader会修改css中background属性,为了准确计算转化后的background属性,请你遵循以下规范:
84+
只要你遵循以下规范,loader会在css中引入生成的雪碧图作为新的背景图,并替换background-size、background-position等属性。
8385

8486

8587
属性名 | 是否必填 | 说明

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
:rocket: [中文文档点这里](https://github.com/sunft1996/sprite-smith-loader/blob/master/README.CN.md/)
88
## Introduce
9-
Sprite Smith loader is a tool for automatically generating CSS Sprites. You can use it in webpack. It will automatically generate CSS Sprites and modify the corresponding CSS code.
9+
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.
1010

1111
supports **CSS****SASS****LESS**.
12+
13+
The picture should be in PNG format (do not directly change the picture suffix to PNG)
1214
## Getting Started
1315
To begin, you'll need to install sprite-smith-loader:
1416

@@ -40,7 +42,7 @@ module.exports = {
4042
},
4143
};
4244
```
43-
with SaSS
45+
with SASS
4446

4547
```
4648
module.exports = {
@@ -64,7 +66,7 @@ module.exports = {
6466
```
6567

6668
## Usage
67-
Modify your CSS/SCSS/SASS/LESS file
69+
Change the picture name to_ sprite.png End and reference it in CSS
6870
```
6971
.my_bg_1{
7072
height: 100px;

demo/loaders/sprite-smith-loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ module.exports = function (source) {
174174
return;
175175
}
176176
}
177+
// 没有定义background-position
178+
if(bgLineEnd == node.sourceIndex && x === undefined && y === undefined){
179+
node.value = - coord[item.url].x * ratio + 'px ' + - coord[item.url].y * ratio + 'px;'
180+
}
177181
});
178182
}
179183
}

dist/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ module.exports = function (source) {
174174
return;
175175
}
176176
}
177+
// 没有定义background-position
178+
if(bgLineEnd == node.sourceIndex && x === undefined && y === undefined){
179+
node.value = - coord[item.url].x * ratio + 'px ' + - coord[item.url].y * ratio + 'px;'
180+
}
177181
});
178182
}
179183
}

0 commit comments

Comments
 (0)