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

makestatic-inline-data

v1.1.8

Published

Convert resource references to data URIs

Downloads

6

Readme

Inline Data

Convert resources to data URIs



Install

yarn add makestatic-inline-data

API

InlineData

Inline references to assets (that exist in the site structure) using data: URIs.

Useful for those critical (above the fold) small assets that are better inlined into the content.

For each matched file find resources that match the rules assigned to the plugin and replace the resource URI with a data: URI containing the file content.

It can operate on resources in HTML and CSS files but you need to have configured the appropriate parsers and generated the resource graph. To illustrate the configuration below would inline all resources ending in logo.png in all HTML and CSS files in the site.

const parse = require('makestatic-preset-parse')
module.exports = {
  lifecycle: {
    parse: parse({js: false}),
    graph: require('makestatic-graph-resources'),
    transform: {
      plugin: require('makestatic-inline-data'),
      rules: [
        {
          test: /logo\.png$/
        }
      ]
    }
  }
}

See Also

InlineData

new InlineData(context, options)

Create an InlineData plugin.

Enable this plugin for the transform phase.

For each matched file convert resources to inline data: URIs according to the assigned rules.

Rules are objects with the following fields:

  • test: regular expression pattern compared against the resource URI.
  • encode: boolean indicating whether to base64 encode the file content.

The test field is required and must be a valid regular expression. By default the encode flag is true and resources are base64 encoded however sometimes it may be more efficient (for svg images with gzip compression) to not base64 encode in which case set the encode field to false.

When the encode rule property is disabled the content is escaped using the encodeURIComponent function.

The mime type for referenced resources is resolved automatically.

  • context Object the processing context.
  • options Object the plugin options.
Options
  • remove Boolean=false delete matched resources.
  • rules Array list of resource matching rules.
Throws
  • Error if no resource graph is available.

.before

InlineData.prototype.before()

Initialize the list of matched resources used in the after hook to delete matched resources when the remove option is set.

.sources

InlineData.prototype.sources(file, context)

Convert resources for each matched file.

  • file Object the current file.
  • context Object the processing context.

.after

InlineData.prototype.after(context)

Deletes matched resources from the compilation assets when the remove option has been enabled.

  • context Object the procesing context.

License

MIT


Created by mkdoc on March 13, 2017