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

posthtml-webp

v2.2.0

Published

Add webp supporting in your html

Downloads

313

Readme

posthtml-webp

NPM Deps Build Coverage Standard Code Style Chat

This plugin add webp supporting in your html. Also supports <amp-img>

Install

$ npm i posthtml posthtml-webp

Usage

const fs = require('fs');
const posthtml = require('posthtml');
const posthtmlWebp = require('posthtml-webp');

posthtml()
    .use(posthtmlWebp(/* Plugin options */))
    .process(html/*, options */)
    .then(result => fs.writeFileSync('./after.html', result.html));

Example

Before:

<img src="image.jpg">
<amp-img alt="photo" width="550" height="368" layout="responsive" src="photo.png"></amp-img>

After:

<picture>
    <source type="image/webp" srcset="image.jpg.webp">
    <img src="image.jpg">
</picture>
<amp-img alt="photo" width="550" height="368" layout="responsive" src="photo.png.webp">
    <amp-img alt="photo" width="550" height="368" layout="responsive" src="photo.png" fallback=""></amp-img>
</amp-img>

Options

extension

Type: string Default: .webp Description: Add custom extension or even prefix Example: image.jpg => image.jpg?as=webp (instead of image.jpg.webp)

replaceExtension

Type: Boolean Default: false Description: Replace the extension of the source image with .webp instead of appending .webp to the original filename Example: image.jpg => image.webp (instead of image.jpg.webp)

classIgnore

Type: Array<string> Default: [] Description: list of classes for which the transformation will be ignored Example: classIgnore: ['ignore-webp'] will ignore transformation for images with the class ignore-web

extensionIgnore

Type: Array<string> Default: [] Description: list of extension for which the transformation will be ignored Example: extensionIgnore: ['svg'] will ignore transformation for images with the svg extension

lazySrcset

Type: String Default: data-srcset Description: The attribute used for lazy webp loading. Use it if you have lazy attribute for srcset on your images. It will be set on created <source> to later be processed by external lazy loading library. Example: lazySrcset: 'my-srcset' will set my-srcset attribute on <source>

lazySrc

Type: String Default: data-src Description: The attribute used for lazy webp loading. The original <img> may not contain src at all, but instead some custom lazy-loading attribute. Or it may contain just a placeholder image inside src which shouldn't be used for webp conversion. lazySrc will define a custom attribute name to look at when processing your lazy loaded images. Note that lazySrcset is still needed even if <img> has only lazySrc defined, because srcset is the mechanism for defining a source file for the <source>. See lazySrcset option description. Example: lazySrc: 'my-src' will convert an image inside my-src attribute, instead of regular src.

License MIT