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

steal-bundle-manifest

v1.0.4

Published

Bundle manifest tools for steal

Downloads

2

Readme

steal-bundle-manifest

Build Status npm version

steal-bundle-manifest is a set of tools that help with working on bundle manifest files; these are files that specify a list of assets associated with a given route. In steal, these routes are keyed as module names.

Install

npm install steal-bundle-manifest --save

Usage

The main export is a constructor function. Instantiating it will give you an object that can be used to pull information from a manifest. A typical usage looks like:

var BundleManifest = require("steal-bundle-manifest");
var spdy = require("spdy");

var manifest = new BundleManifest({
  serverRoot: "/assets"
});

spdy.createServer({
  cert: ...,
  key: ...,
  protocols: ["h2", "http/1.1"]
}, function(req, res){
  if(req.url === "orders") {

    var route = manifest.for("app/orders/");

    // Calling push will cause the assets to be pushed in HTTP2.
    route.push(req, res);

    var styles = route.assets.filter(a => a.type === "style");
    var scripts = route.assets.filter(a => a.type === "script");

    res.end(`
      <html>
        <head>
          ${route.toHTML(styles)}
        </head>
        <body>
          <h1>Orders page</h1>

          ${route.toHTML(scripts)}
        </body>
      </html>
    `);

  } else {
    ... other stuff
  }
});

API

BundleManifest

A BundleManifest is a type that represents a bundle manifest file. Upon instantiation you can provide a single argument manifestOptions to specify where files are located.

manifestOptions

An object including the following properties:

manifest

Specify the location of the manifest file. If not provided then process.cwd() + "/dist/bundles.json" is used.

var manifest = new BundleManifest({
  manifest: __dirname + "public/bundles.json"
});
root

Specify the root location from where to find the files listed in the bundle manifest.

var manifest = new BundleManifest({
  root: __dirname + "/public"
});
serverRoot

Specify the server's root, from where it should look for resources. This will influence how assets are written out when using the toHTML() API.

var manifest = new BundleManifest({
  serverRoot: "/assets"
});

Will cause scripts to be written like:

<script src="/assets/dist/bundles/app/app.js"></script>

for

A method used to derive a Route object for a given module name. This lets you filter down the bundle manifest to just the route you are interested in.

var manifest = new BundleManifest();

var route = manifest.for("app/orders/");

route.assets; // -> [ { type: "script", path: "dist/bundles..." } ]
route.push; // function(){}

Route

A Route type is created when using manifest.for(route). This is an object representing a given route (or root bundle). From here you can work with a set of assets for the route, filtering as necessary.

assets

An Array of all of the assets associated with this route. Use normal array methods to further derive subsets as needed. For example, you typically might want to filter the set of assets into scripts and styles so that you can generate HTML snippets for each, or to provide an array for looping in your chosen templating language.

var manifest = new BundleManifest();

var route = manifest.for("app/orders");

var scripts = route.assets.filter(a => a.type === "script");
var styles = route.assets.filter(a => a.type === "style");

push

A function which, given a Node.js request and response, will send PUSH messages when using HTTP/2, and add Preload link headers when using HTTP/1.

This can be used instead of steal-push. A typical usage with Express looks like:

const spdy = require("spdy");
const express = require("express");
const BundleManifest = require("bundle-manifest");

const manifest = new BundleManifest();

app.get("/",
	manifest.for("main").push,
	function(req, res){
		...
	});

app.get("/orders",
	manifest.for("orders/").push,
	function(req, res){
		...
	});

spdy.createServer({
	key: ...,
	cert: ...,
	protocols: ["h2", "http/1.1"]
}, app).listen(8080);

toHTML

This method generates HTML for assets. For scripts it creates <script> tags, for styles, <link> tags.

var scripts = route.assets.filter(a => a.type === "script");

route.toHTML(scripts); // -> "<script src="/dist/bundles/app/app.js" async></script>

License

MIT