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

saber-plugin-pwa

v0.4.4

Published

Add PWA support for your Saber app.

Downloads

6

Readme

saber-plugin-pwa

Add PWA (progressive web app) support to your Saber app.

Install

yarn add saber-plugin-pwa

Usage

In your saber-config.yml:

plugins:
  - resolve: saber-plugin-pwa

Then you need to create a set of icons in static folder to make your app installable, for example:

  • img/icons/icon_128x128.png
  • img/icons/icon_256x256.png
  • img/icons/icon_512x512.png

And create static/manifest.json to include these icons:

{
  "icons": [
    {
      "src": "img/icons/icon_128x128.png",
      "type": "image/png",
      "sizes": "128x128"
    },
    {
      "src": "img/icons/icon_256x256.png",
      "type": "image/png",
      "sizes": "256x256"
    },
    {
      "src": "img/icons/icon_512x512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ]
}

You don't need to worry about other options in manifest.json, this plugin will set default values for them.

Now run saber build and you will get a PWA-ready web app in public folder.

Configure the Text for the Update Notifier

Use siteConfig in your Saber config file to configure the text:

siteConfig:
  # Default values:
  pwaFirstTimeInstallMessage: Ready for offline use
  pwaUpdateFoundMessage: Downloading app updates in the background..
  pwaUpdateReadyMessage: A new version of this app is available
  pwaUpdateButtonMessage: UPDATE
  pwaDismissMessage: DISMISS

Remove Service Worker

If you no longer need this plugin in your website, you should first uninstall this plugin and remove it from your saber-config.yml:

plugins:
-  - resolve: saber-plugin-pwa

Then populate a static/service-worker.js file as follows:

self.addEventListener('install', function(e) {
  self.skipWaiting()
})

self.addEventListener('activate', function(e) {
  self.registration
    .unregister()
    .then(function() {
      return self.clients.matchAll()
    })
    .then(function(clients) {
      clients.forEach(client => client.navigate(client.url))
    })
})

The snippet tells your browser to remove previsously installed service worker and refresh.

Options

name

  • Type: string
  • Default: siteConfig.title | 'Saber PWA App'

The name for your PWA. You can also directly configure the name in your manifest.json to override this.

themeColor

  • Type: string
  • Default: #ffffff

The theme color for your PWA. You can also directly configure the theme_color in your manifest.json to override this.

assetsVersion

  • Type: string
  • Default: ''

This option is used if you need to add a version to your manifest.json, against browser’s cache. This will append ?v=assetsVersion to the URL of the manifest.

appleTouchIcon

  • Type: string

The URL to the apple touch icon, for example img/icons/apple-touch-icon-152x152.png, used by iOS devices. When this is not set we automatically use icons from your manifest.json.

notifyUpdates

  • Type: boolean
  • Default: true

Pop up an update notifier when a new update for your app if available.

You can disable this with notifyUpdates: false and use your custom update notifier in saber-browser.js:

// `workbox` is injected by this plugin
export default ({ workbox }) => {
  if (process.browser && workbox) {
    workbox.addEventListener('installed', event => {
      if (!event.isUpdate) {
        showUpdateNotifier({
          message: 'Ready for offline use'
        })
      }
    })

    workbox.addEventListener('waiting', () => {
      showUpdateNotifier({
        message: 'An update is ready, click to apply',
        clicked() {
          workbox.addEventListener('controlling', event => {
            window.location.reload()
          })

          workbox.messageSW({ type: 'SKIP_WAITING' })
        }
      })
    })
  }
}

Then just implement your own showUpdateNotifier function. Check out workbox-window for the details of the workbox object.

generateSWOptions

  • Type: object

Options for the generateSW API from workbox-build.

License

MIT.