npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-webp

v1.0.4

Published

Rollup plugin for convert images to webp

Downloads

15

Readme

rollup-plugin-webp

A rollup plugin for convert images to webp. After building, the same name webp files will be generated in the directory of files ending with .jpg, .jpeg, .png, and .gif suffixes.

这是一个用于将图片转换成Webp格式的rollup插件,构建时会在.jpg、.jpeg、.png、.gif后缀结尾的文件的目录下生成一个.webp格式的同名文件。

Usage

Install

npm i rollup-plugin-webp -D

Config

const { webp } = require('rollup-plugin-webp');

export default {
    ...
    plugins: [
        ...
        webp()
    ]
}

Options

You can provide parameters to control the details of the conversion.

你可以传入参数控制转换的细节。

webp({
    quality: 80,
    include: ['valentinesDayActivity'], // regular expressions or string
})

|Key|Type|Default|Description| |----|----|----|----| |quality|number|80|The quality of the generated webp file (1-100), the larger the number, the higher the quality of the file and the larger the space occupied| |include|(string\|RegExp)[]|[]|Folders that need to be included (whitelist mode), you can provide regular expression or string, and the string will be converted to a regular expression like new RegExp(`/${yourString}/`)| |exclude|(string\|RegExp)[]|[]|Folders that need to be excluded (blacklist mode), regular expressions or strings can be provided|

Tips

Not all devices support the Webp format, please do not use webp format images directly in the project, the following is a usage of the Vue framework.

不是所有的设备都可以兼容Webp格式的图片,使用前请做好webp兼容性测试,以下是Vue框架中的一种用法。

// CustomDirectives.js
let isSupportWebp = false;
const checkWebpSupport = () => {
    const img = new Image();
    img.onload = () => {
        isSupportWebp = img.width > 0 && img.height > 0;
    };
    img.onerror = () => {
        isSupportWebp = false;
    };
    img.src = `data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==`;
};
checkWebpSupport();

const src = {
    beforeMount(el, binding) {
        const targetFileSrc = new URL(
            `../assets/images/${binding?.value}`,
            import.meta.url
        )?.href;
        const webpFileName = targetFileSrc?.replace(/(.jpg)|(.jpeg)|(.png)|(.gif)$/i, '.webp');
        const s = isSupportWebp ? webpFileName : targetFileSrc;
        el.onerror = () => {
            el.src = targetFileSrc;
            el.onerror = null;
        };
        if (s) el.src = s;
    },
};
export default {
    src
};
// main.ts
import { src } from '@utils/CustomDirectives';
const app = createApp(App);
app.directive('src', src); // Register this custom directive globally
app.mount('#app');
<!-- If the device supports webp, it actually points to 'assets/images/banner.webp' -->
<img v-src="'banner.jpg'"/>

Github

Github

This is a very simple plugin for our internal project, it has not been rigorously tested by Jest. If you are interested in it, welcome to commit pull request to improve this plugin.

这是一个用于我们业务项目的非常简单的插件,并未经过严谨的Jest测试,如果你有兴趣,欢迎发起pr请求完善此插件。