Skip to content

Commit 6a1f23f

Browse files
committed
压缩CSS样式代码
1 parent 4975d57 commit 6a1f23f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

compressCss.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @description 压缩CSS样式代码
3+
* @author 未知
4+
*/
5+
6+
function compressCss (s) {//压缩代码
7+
s = s.replace(/\/\*(.|\n)*?\*\//g, ""); //删除注释
8+
s = s.replace(/\s*([\{\}\:\;\,])\s*/g, "$1");
9+
s = s.replace(/\,[\s\.\#\d]*\{/g, "{"); //容错处理
10+
s = s.replace(/;\s*;/g, ";"); //清除连续分号
11+
s = s.match(/^\s*(\S+(\s+\S+)*)\s*$/); //去掉首尾空白
12+
return (s == null) ? "" : s[1];
13+
}

0 commit comments

Comments
 (0)