6.46.8 • Published 4 days ago

@gasket/plugin-manifest v6.46.8

Weekly downloads
39
License
MIT
Repository
github
Last release
4 days ago

@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

gasket create <app-name> --plugins @gasket/plugin-manifest

Existing apps

npm i @gasket/plugin-manifest

Modify plugins section of your gasket.config.js:

module.exports = {
  plugins: [
    add: [
+      '@gasket/plugin-manifest'
    ]
  ]
}

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.config.js:

// gasket.config.js
module.exports = {
  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.config.js
module.exports = {
  manifest: {
    // other options
    path: '/custom/path/manifest.json' // default: /manifest.json
  }
}

Lifecycles

manifest

Another option to adjust the manifest if 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).

// lifecyles/manifest.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
 */
module.exports = 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.config.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:

// lifecycles/workbox.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
 */
module.exports = function (gasket, config, req) {
  const { icons = [] } = req.manifest;

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

License

MIT

7.0.0-next.21

4 days ago

7.0.0-next.9

8 days ago

7.0.0-next.10

8 days ago

7.0.0-next.7

9 days ago

7.0.0-next.11

8 days ago

7.0.0-next.8

8 days ago

7.0.0-next.12

8 days ago

7.0.0-next.13

8 days ago

7.0.0-next.6

9 days ago

7.0.0-next.20

8 days ago

7.0.0-next.5

9 days ago

6.46.8

11 days ago

7.0.0-next.4

11 days ago

7.0.0-next.3

15 days ago

7.0.0-next.2

23 days ago

7.0.0-next.1

23 days ago

7.0.0-next.0

23 days ago

7.0.0-cli.7

2 months ago

7.0.0-cli.6

2 months ago

6.46.1-cli.0

2 months ago

7.0.0-cli.5

2 months ago

7.0.0-cli.4

2 months ago

7.0.0-cli.1

2 months ago

7.0.0-cli.0

2 months ago

7.0.0-cli.3

2 months ago

7.0.0-cli.2

2 months ago

6.46.3-cli.0

2 months ago

6.46.2

2 months ago

7.0.0-canary.1

2 months ago

6.46.2-esm.0

2 months ago

6.45.2

3 months ago

6.45.0

4 months ago

6.43.0

7 months ago

6.39.3

11 months ago

6.39.0

12 months ago

6.38.8

12 months ago

6.38.5

1 year ago

6.38.1

1 year ago

6.36.1

1 year ago

6.38.0

1 year ago

6.34.6

2 years ago

6.36.0

1 year ago

6.34.3

2 years ago

6.34.4

2 years ago

6.34.2

2 years ago

6.26.1

2 years ago

6.28.0

2 years ago

6.27.1

2 years ago

6.21.0

2 years ago

6.24.2

2 years ago

6.24.0

2 years ago

6.20.4

2 years ago

6.20.3

2 years ago

6.20.2

2 years ago

6.19.0

2 years ago

6.17.0

2 years ago

6.15.2

2 years ago

6.11.0

2 years ago

6.10.1

2 years ago

6.10.0

2 years ago

6.14.0

2 years ago

6.11.2

2 years ago

6.0.12

3 years ago

6.0.0

3 years ago

6.0.0-canary.13

3 years ago

6.0.0-canary.11

3 years ago

6.0.0-canary.9

3 years ago

6.0.0-canary.6

3 years ago

6.0.0-canary.0

4 years ago

5.6.0

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

5.0.0-canary.4

4 years ago

5.0.0-canary.3

4 years ago

5.0.0-canary.2

4 years ago

5.0.0-canary.1

4 years ago

5.0.0-canary.0

4 years ago