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

eleventy-plugin-local-images

v0.4.1

Published

a plugin to grab remote images and serve them locally

Downloads

1,000

Readme

eleventy-plugin-local-images

What is this plugin for?

If you are pulling your Eleventy content from a cloud-based CMS or third-party API, then chances are high that any images referenced in the content will also be hosted in cloud storage. However, Harry Roberts has suggested that it is usually more performant to self-host your static assets rather than host them on a CDN (source).

This plugin is a post-processor that looks for image paths within your generated site, pulls down a uniquely-hashed local copy of each remote image and updates the filepaths in markup - That way you can be confident that your site's images will still be working, even if your CMS or cloud storage goes down.

Install the plugin

From your project directory run:

npm install eleventy-plugin-local-images --save-dev

Once the package has installed, open up your .eleventy.js file.

Step 1: Require the plugin

const localImages = require('eleventy-plugin-local-images');

Step 2: Configure and add the plugin:

module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(localImages, {
    distPath: '_site',
    assetPath: '/assets/img',
    selector: 'img',
    verbose: false
  });
};

Configuration options

| Key | Type | Description | |--|--|--| | distPath | String | The output folder for your eleventy site, e.g. '_site'Required | | assetPath | String | The root-relative folder where your image assets are stored, e.g. '/assets/img'Required | | selector | String | The css selector for the images you wish to replace. This defaults to all images 'img', but could be used to fence certain images only, e.g. '.post-content img'Default: 'img' | | attribute | String | The attribute containing the image path. This defaults to 'src', but could be used to match other attributes, e.g. 'srcset' if targeting a <picture><source>, or 'data-src' if using a lazy-loading pluginDefault: 'src' | | verbose | Boolean | Toggles console logging when images are saved locallyDefault: false |

Known issues

Currently, as all of the image checks are carried out asynchronously, if multiple <img> tags exist with the same src attribute, the plugin will attempt to download the file for each instance of the path.

This isn't as efficient as it should be, however the plugin will always save the file with the same hashed filename, so it will at least not result in duplicated files on your local storage.

Contributing

I'm really happy to consider any contributions to this plugin. Before you make any changes, please read the contribution guide.