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 🙏

© 2026 – Pkg Stats / Ryan Hefner

webp-responsive-loader

v1.0.3

Published

converts image files to webp format and adds to the project build

Readme

webp-responsive-loader

npm node

Загрузчик webpack для адаптивных изображений. Создает несколько изображений формата .webp из одного исходного изображения и возвращает srcset и sizes. Чтобы иметь представление что такое адаптивные изображение можете пройти сюда Responsive Images.

Установка

npm

npm install webp-responsive-loader --save-dev

yarn

yarn webp-responsive-loader -D

Использование

Добавьте правило для загрузки адаптивных изображений в конфигурацию вашего webpack:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.(jpe?g|png|bmp)$/i,
        use: {
          loader: "responsive-loader",
          options: {
            name: "[path][name].[ext]", // параметр name является обязательным для работы лоадера
          },
        },
      },
    ],
  },
};

Затем импортируйте изображения в свои файлы JavaScript:

import responsiveImage from 'img/myImage.jpg';

...
    <img
      srcSet={responsiveImage.srcset}
      sizes={responsiveImage.sizes}
    />
...

Примечания:

  • sizes, без размеров браузер предполагает, что изображение всегда 100vw для любого окна просмотра.
  • srcset, Современные браузеры будут выбирать наиболее близкое к изображению лучшее изображение в зависимости от плотности пикселей вашего экрана.

Параметры

| Параметр | Тип | Default | Описание | | --------------------------- | -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | string | undefined | Это обязательный параметр. Шаблон имени файла для выходных файлов. | | publicPath | string | undefined | Папка, в которую будут помещены при сборке проекта file. | | emitOriginalFile | boolean | undefined | Если true, то добавляет оригинальный файл в сборку и возвращает путь к нему в переменной srcOriginal | | resizeList | array integer | [320, 720, 1080] | Ширина новых webp файлов. Данный список используется когда нужно передать свои размеры конечных фалов webp | | placeholder | string | undefined | placeholder. Будет показан пока основное изображение загружается |

Пример использования

Добавьте пдобные инструкции в настройки webpack. webpack.config.js

module.exports = {
  entry: {...},
  output: {...},
  module: {
    rules: [
      {
        test: /\.(jpe?g|png|bmp)$/i,
         use: [
          {
            loader: "webp-responsive-loader",
            options: {
              name: "[path][name].[ext]",
              resizeList: [320, 960, 1800],
              placeholder: true,
              publicPath: "images"
            },
          },
        ],
      }
    ]
  },
}

component.js

import responsiveImage from 'img/myImage.jpg';
...
    <img
      srcSet={responsiveImage.srcset}
      sizes={responsiveImage.sizes}
      placeholder={responsiveImage.placeholder}
    />
...

Typescript

Если в вашем проекте используется typescript, то вы можете использовать файл деклараций.

tsconfig.json

{
...
    "compilerOptions": {
      ...
      "typeRoots": ["src/typings"],
      ...
    }
}

src/typings/types.d.ts

...
/// <reference types="webp-responsive-loader" />
...