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

rollup-plugin-hash-n-gzip

v3.0.0

Published

Hash and gzip output files

Downloads

12

Readme

rollup-plugin-hash-n-gzip

Hash and gzip outputs. Updated for Rollup 0.64+.

Used for static serving of gzip compressed files with filename based cache busting and source integrity calculation.

Combine with rollup-plugin-web-build-events for an integrated live-reload development experience.

Example

Generate a static public/ folder with gzip'd files and a preprocessed public/index.html and public/dynamic.json. Then serve with packages like express-static-gzip or koa-static.

import rpi_hash_n_gzip from 'rollup-plugin-hash-n-gzip'

const plugins = [rpi_hash_n_gzip({onAltMapping, altBase})]

export default [
	{ input: ['src/main-a.js', 'src/main-b.js'],
		output: { dir: 'public/module', format: 'es', sourcemap: true },
		plugins, experimentalCodeSplitting: true },
]


let tid
function onAltMapping(altNames, altRoot, ns) {
  Object.assign(ns, altNames)
  console.log(`onAltMapping for "${altRoot}"`)

  // debounce rebuilding depenent outputs as necessary. (e.g. index.html)
  clearTimeout(tid)
  tid = setTimeout(rebuildRoot, 100, ns)
}

function rebuildRoot(ns) {
  fs.writeFile('public/dynamic.json',
    JSON.stringify(ns, null, 2),
    err => err && console.error(err) )

  // Or use a templating engine here
  const index_html = `\
<!doctype html>
<head>
  <title>rollup-plugin-hash-n-gzip example</title>
  <script type=module src='${ns['public/module/main-a.js']}'></script>
  <script type=module src='${ns['public/module/main-b.js']}'></script>
</head>
<body>
  Look in your inspector
</body>`

  fs.writeFile('public/index.html', index_html,
    err => err && console.error(err) )
}

Rollup Plugin Options

import rpi_hash_n_gzip from 'rollup-plugin-hash-n-gzip'

const plugins = [
  rpi_hash_n_gzip({
    minSize: 14e3, // souces over this size will be gzip'd
    gzip_options: null, // zlib gzip options
    hash_algorithm: 'sha1',
    skip(outputFileName, bndl) {}, // allows excluding some bundles from processing (e.g. code splits)

    contentBase: null, // path that resolved updates are relative to
    onBuildUpdate({updates}) {}, // callback for each generateBundle processing
  })
]

License

MIT

Some code inspired and/or sourced from: