You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vite-plugin-sprites

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-sprites - npm Package Compare versions

Comparing version

to
0.2.0

8

dist/index.js
/**
* name: vite-plugin-sprites
* version: 0.1.0
* version: 0.2.0
*/
import d from"fs";import u from"path";import{createCanvas as S,Image as C}from"canvas";var f,x=(e,n)=>{let r=u.join(f,e,n);return u.relative(f,r)},W=e=>{let{iconPath:n="/src/assets/icon"}=e,r=u.join(f,n);d.readdir(r,(c,g)=>{if(c)throw c;let p=g.filter(i=>(i.endsWith(".jpg")||i.endsWith(".png"))&&i!=="sprites.png"),h=p.length,a=0,s=[];p.forEach(i=>{let o=new C;o.onload=()=>{s.push({path:i,width:o.width,height:o.height,image:o}),a++,a===h&&j(s,e)},o.src=x(n,i)})})},j=(e,n)=>{let{savePath:r="/src/assets/icon",width:c=500,spacing:g=5,prefix:p="icon-"}=n;e.sort((t,l)=>t.height<l.height?-1:t.height>l.height?1:0);let h=0,a=0,s=0;e.forEach(t=>{t.width+h+g>c?(a+=s+g,h=0,s=0,t.x=t.x||0):t.x=t.x||h,t.height>s&&(s=t.height),t.y=t.y||a,h+=t.width+g});let i=a+s,o=S(c,i),$=o.getContext("2d"),w=x(r,"sprites.png"),b=`[class*="${p}"]:before{content:"";background-image: url(./sprites.png); display:flex;align-items: center}
`;e.forEach(t=>{$.drawImage(t.image,t.x,t.y,t.width,t.height);let l=t.path.substring(0,t.path.indexOf(".")),m=t.x?`-${t.x}px`:0,y=t.y?`-${t.y}px`:0;b+=`.${p+l}:before{background-position: ${m} ${y};width: ${t.width}px;height: ${t.height}px}
`});let v=x(r,"sprites.css");d.writeFile(`${v}`,b,function(t){if(t)throw t;console.log(`\u6210\u529F\u5199\u5165css\u6587\u4EF6:${v}`)});let P=d.createWriteStream(w);o.createPNGStream().pipe(P),P.on("finish",()=>console.log(`\u6210\u529F\u5408\u5E76\u56FE\u7247:${w}`))},E=e=>({name:"vitePluginSprites",enforce:"pre",configResolved(n){f=n.root},buildStart(){W(e)},load(){}}),L=E;export{L as default};
import b from"fs";import u from"path";import x from"images";var w=(s,e,o)=>{let h=u.join(s,e,o);return u.relative(s,h)},m=(s={})=>{let{iconPath:e="/src/assets/icon",root:o="./"}=s,h=u.join(o,e);b.readdir(h,(c,g)=>{if(c)throw c;let p=g.filter(r=>(r.endsWith(".jpg")||r.endsWith(".png"))&&r!=="sprites.png"),i=p.length,a=0,n=[];console.log(`\u68C0\u6D4B\u5230${i}\u4E2A\u56FE\u7247\u6587\u4EF6\uFF0C\u5F00\u59CB\u8FDB\u884C\u5408\u5E76~`),p.forEach(r=>{let l=w(o,e,r),f=x(l).size();n.push({path:l,width:f.width,height:f.height}),a++,a===i&&C(n,s)})})},C=(s,e)=>{let{root:o="./",savePath:h=e.iconPath||"/src/assets/icon",width:c=500,spacing:g=5,prefix:p="icon-"}=e;s.sort((t,d)=>t.height<d.height);let i=0,a=0,n=0;s.forEach(t=>{t.width+i+g>c?(a+=n+g,i=0,n=0,t.x=t.x||0):t.x=t.x||i,t.height>n&&(n=t.height),t.y=t.y||a,i+=t.width+g});let r=a+n,l=x(c,r),f=w(o,h,"sprites.png"),P=`[class*="${p}"]:before{content:"";background-image: url(./sprites.png); display:flex;align-items: center}
`;s.forEach(t=>{l.draw(x(t.path),t.x,t.y);let d=t.path.substring(0,t.path.indexOf(".")),S=t.x?`-${t.x}px`:0,j=t.y?`-${t.y}px`:0;P+=`.${p+d}:before{background-position: ${S} ${j};width: ${t.width}px;height: ${t.height}px}
`});let v=w(o,h,"sprites.css");b.writeFile(`${v}`,P,function(t){if(t)throw t;console.log(`\u6210\u529F\u5199\u5165css\u6587\u4EF6\uFF1A${v}`)}),l.save(f),console.log(`\u6210\u529F\u5408\u5E76\u56FE\u7247\uFF1A${f}`)},$=m;var y=s=>({name:"vitePluginSprites",enforce:"pre",configResolved(e){s.root=e.root},buildStart(){$(s)}});y.images=$;var z=y;export{z as default};
{
"name": "vite-plugin-sprites",
"version": "0.1.0",
"version": "0.2.0",
"description": "一款基于NodeJs的图片合成Vite插件,可将多张小图合并成一张大图并生成对应的css样式,可有效减少服务器接收和发送请求,提高页面加载速度。",

@@ -47,3 +47,3 @@ "license": "MIT",

"dependencies": {
"canvas": "^2.11.2"
"images": "^3.2.4"
},

@@ -50,0 +50,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet