🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

vite-plugin-images-sharp

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-images-sharp - npm Package Compare versions

Comparing version

to
1.0.2

pnpm-lock.yaml

4

lib/vite-plugin-images-sharp.esm.js
/*!
* vite-plugin-images-sharp v1.0.1
* (c) Mon Mar 20 2023 17:03:23 GMT+0800 (China Standard Time) lbr
* vite-plugin-images-sharp v1.0.2
* (c) Thu Feb 06 2025 10:45:33 GMT+0800 (China Standard Time) lbr
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

/*!
* vite-plugin-images-sharp v1.0.1
* (c) Mon Mar 20 2023 17:03:23 GMT+0800 (China Standard Time) lbr
* vite-plugin-images-sharp v1.0.2
* (c) Thu Feb 06 2025 10:45:33 GMT+0800 (China Standard Time) lbr
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

/*!
* vite-plugin-images-sharp v1.0.1
* (c) Mon Mar 20 2023 17:03:23 GMT+0800 (China Standard Time) lbr
* vite-plugin-images-sharp v1.0.2
* (c) Thu Feb 06 2025 10:45:33 GMT+0800 (China Standard Time) lbr
* Released under the MIT License.
*/
"use strict";var e=require("fs"),t=require("path"),r=require("sharp");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(e),o=n(t),a=n(r);function c(e){try{return window.eval(e)}catch(t){return e}}var s={toArray:function(e){return"string"==typeof e?e?[e]:[]:e},isDirectory:function(e){return i.default.statSync(e).isDirectory()},evalCatch:c,isTargetImage:function(e,t){const r=c(e).split("."),n=r[r.length-1];return t.includes(`.${n}`)},getWebpPath:function(e,t,r,n){const i=e.split("."),o=i[i.length-1],a=new RegExp(`${o}$`);return e.replace(a,n).replace(t,r)}};const u=/\D+(\d+)[xX*](\d+)\.webp$/;function l(e,t){if(!1===i.default.existsSync(e))return;const{imageType:r,entry:n,outDir:c,sharpType:p}=t;i.default.readdirSync(e).forEach((i=>{const f=o.default.join(e,i);s.isDirectory(f)?l(f,t):s.isTargetImage(f,r)&&(Array.isArray(p)?p.forEach((e=>{const t=s.getWebpPath(f,n,c,e);((e,t,r)=>{let n=null,i=null;u.lastIndex=0,u.test(t)&&(n=Number(RegExp.$1),i=Number(RegExp.$2)),new Promise(((o,c)=>{if("avif"===r)try{a.default(e).resize({width:n,height:i}).avif().toFile(t,((e,t)=>{e?c(e):o(t)}))}catch(e){c(e)}else try{a.default(e).resize({width:n,height:i}).webp().toFile(t,((e,t)=>{e?c(e):o(t)}))}catch(e){c(e)}}))})(f,t,e)})):console.error("sharpType需为数组"))}))}const p=e=>{const{entry:t}=e,r=s.toArray(t);for(let t=0;t<r.length;t++){l(r[t],e)}};module.exports=function(e={}){const t=Object.assign({entry:"",imageType:[".png",".jpg"],sharpType:["webp"],outDir:"",compileTime:"after"},e);return"before"===t.compileTime&&p(t),{name:"vite-plugin-images-sharp",enforce:"post",closeBundle(){"after"===t.compileTime&&(p(t),console.info("图片转换结束"))}}};
{
"name": "vite-plugin-images-sharp",
"version": "1.0.1",
"version": "1.0.2",
"private": false,

@@ -33,3 +33,3 @@ "description": "vite插件,转换webp、avif格式",

"dependencies": {
"sharp": "0.30.5"
"sharp": "0.33.5"
},

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