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

webpack-progressive-image

v1.0.2

Published

Webpack plugin for progressive image formats

Downloads

7

Readme

#Webpack Progressive Image Plugin Converts you images to progressive formats in a plug-and-play way.

Table of Contents

Motivation

Chrome-based browsers can take the advantage of progressive image formats, such as webp.

  • smaller: webp images are significantly smaller than regular (usually by around 25%)
  • faster: since they smaller we take less time to download them
  • better: Google will give you higher score for performance which can affect your search positions!

Usage

I use this solution with react-create-app, but it doesn't depend on any of its configs

When you use images in your code, add progressive before their extension to make them processed by plugin's loader

It's very important to import your image before using, otherwise Webpack will not process it with loader

So, <img> in yours

import mainImageUrl from './main-image.progressive.jpg';

const AboutComponent = props => {

  return <div>
       <img src={mainImageUrl} alt={'About us'} />
    </div>
  };
}

export default AboutComponent;

will be replaced by

<picture>
    <source srcset="/static/media/main-image.progressive.36272843.webp" type="image/webp">
    <source srcset="/static/media/main-image.progressive.36272843.jpg" type="image/jpeg">
    <img src="/static/media/main-image.progressive.36272843.jpg" alt="О нас">
</picture>

during the building process.

What about css?

Well, the same result we can achieve in our css by using postcss-plugin

Let's imagine that we have following sass code with background-image declaration

.hero {
	height: 700px;
	background: {
		image: url('./background.progressive.jpg');
	}
}

By the end we will have something like that

.styles_hero__1g47g {
  height: 700px;
}

body.no-webp .styles_hero__1g47g {
  background-image: url(/static/media/background.progressive.b759c5d7.jpg);
}

body.webp .styles_hero__1g47g {
  background-image: url(/static/media/background.progressive.b759c5d7.webp);
}

I stole this solution here and modified a little to work with webpack loader.

Installation

  1. Install this plugin by your favorite package manager

    yarn add webpack-progressive-image
  2. This plugin consists of three parts - webpack-loader, babel-plugin and postcss-plugin. You need to add them all to your webpack configuration. I suggest using customrize-cra for this purpose.

    const { override, addBabelPlugin, addPostcssPlugins, addWebpackModuleRule} = require("customize-cra");
    
    const BabelPlugin = require("webpack-progressive-image/dist/babel-plugin");
    const PostCssPlugin = require("webpack-progressive-image/dist/postcss-plugin");
    const WebpackLoader = require("webpack-progressive-image");
    
    module.exports = override(
        addBabelPlugin(BabelPlugin),
        addPostcssPlugins([PostCssPlugin()]),
        addWebpackModuleRule(WebpackLoader)
    );
  3. In order to make our postcss-plugin work, we have to check whether webp is available or not. To do this, just include this very tiny checker in your index.js

    import React from 'react';
    import ReactDOM from 'react-dom';
    import App from './App';
    import 'webpack-progressive-image/dist/webp-checker'
    
    ReactDOM.render(
        <React.StrictMode>
            <App/>
        </React.StrictMode>,
        document.getElementById('root')
    );

Support

If you find any problems or bugs, please open a new issue.