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

@gasket/plugin-manifest

v7.0.9

Published

The web app manifest for progressive Gasket applications

Downloads

830

Readme

@gasket/plugin-manifest

Adds support for a custom manifest.json to be provided for your application. This allows your application to take full advantage of being a Progressive Web Application. This is useful for progressive web applications, and works best when paired with @gasket/plugin-workbox and @gasket/plugin-service-worker.

Installation

New apps

npm i @gasket/plugin-manifest

Update your gasket file plugin configuration:

// gasket.js

+ import pluginManifest from '@gasket/plugin-manifest';

export default makeGasket({
  plugins: [
+   pluginManifest
  ]
});

Configuration

By default, this plugin will serve {} as your manifest.json. Consumers of this plugin have 2 options in augmenting this object. The first is through gasket.js:

// gasket.js
export default makeGasket({
  manifest: {
    short_name: 'PWAwesome',
    name: 'Progressive Web Application'
  }
});

If you want to serve manifest.json from a custom path, the plugin can be configured as follows.

// gasket.js
export default makeGasket({
  manifest: {
    // other options
    path: '/custom/path/manifest.json' // default: /manifest.json
  }
});

If you want to generate a manifest.json file at build time for use with a static app, the plugin can be configured with the staticOutput option:

// gasket.js
export default makeGasket({
  manifest: {
    // other options
    staticOutput: '/custom/path/manifest.json'
  }
});

You will also need to include a link to your manifest.json file on your static html pages:

<link src="/manifest.json" rel="manifest">

Users also have the option to pass in a boolean value of true, which defaults the path to public/manifest.json.

Lifecycles

manifest

Another option to adjust the manifest is through a lifecycle hook. This lifecycle method is executed every time an incoming http request is made that matches either manifest.json or the service worker script (which is sw.js by default).

// sample-plugin.js

/**
 * Generate a manifest.json that will be deeply merged into the existing ones.
 * In this example, we check if the requesting IP address is valid using an
 * arbitrary function.
 *
 * @param  {Gasket} gasket The Gasket API
 * @param {Object} manifest Waterfall manifest to adjust
 * @param  {Request} req Incoming HTTP Request
 * @return {Promise<Object>} updated manifest
 */
export default {
  name: 'sample-plugin',
  hooks: {
    manifest: async function (gasket, manifest, { req }) {
    const whitelisted = await checkAgainstRemoteWhitelist(req.ip);
    return {
      ...manifest,
      orientation: gasket.config.orientation,
      theme_color: (req.secure && whitelisted) ? '#00ff00' : '#ff0000'
    };
  }
}

It is important to note that conflicting objects from gasket.js and a manifest hook will be resolved by using the data from the hook.

Once the manifest.json has been resolved, it is suggested that consumers of this plugin take advantage of the workbox hook. For example: here we cache any icons that the application might use at runtime:

// sample-plugin.js

/**
 * Returns a config partial which will be merged
 * @param {Gasket} gasket The gasket API
 * @param {Object} config workbox config
 * @param {Request} req incoming HTTP request
 * @returns {Object} config which will be deeply merged
 */
export default {
  name: 'sample-plugin',
  hooks: {
    workbox: function (gasket, config, req) {
      const { icons = [] } = req.manifest;

    return {
      runtimeCaching: icons.map(icon => ({
        urlPattern: icon.src,
        handler: 'staleWhileRevalidate'
      }))
    };
  };
}

License

MIT