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

sw-build-tools

v0.2.0

Published

Service Worker build tools.

Downloads

4

Readme

sw-build-tools

Service Worker build tools.

Installation

npm install --save-dev sw-build-tools

Quickstart - Generate a Service Worker config file

/* # Quickstart 
 *
 * The following generates a `service-worker-config.js`
 * file which contains a prefetch array as is used for
 * precaching resources with a Service Worker.
 *
 * The file will be saved in the `dist` directory, and 
 * will contain all resources found in the `src/assets` 
 * directory. 
 *
 * It will also include root (`/`) and the `bundle.js`
 * file (even if it does not exist yet). 
 */

const tools = require('sw-build-tools')

tools.generateConfig({
  prefetchResources: [
    'bundle.js'
  ],
  prefetchResourceGlobs: [
    'assets/**'
  ]
})

/* **Example output in the config file:**
 *
 *   ```
 *   navigator.serviceWorkerConfig = {
 *     prefetch: [
 *       '/',
 *       '/bundle.js',
 *       '/assets/favicon.ico'
 *     ]
 *   }
 *   ```
 *
 * After this, you can import the config in your
 * Service Worker:
 *
 *   ```
 *   importScripts('service-worker-config.js')
 *   ```
 *
 * And add the resources that are supposed to be
 * prefetched to the cache:
 *
 *   ```
 *   cache.addAll(navigator.serviceWorkerConfig.prefetch)
 *   ```
 *
 * # Why should you use this module?
 *
 * a) It's more lightweight and customizable than Google's
 *    'sw-precache' (github.com/GoogleChrome/sw-precache)
 *
 * b) You haven't yet tried Service Worker, and you know 
 *    you absolutely should
 * 
 * # Why are you writing all this in a gigantic JavaScript 
 * comment that includes Markdown syntax which is placed 
 * in a JavaScript code block in a Markdown Readme?
 * 
 * - ... whatever.
 */

API - tools.generateConfig(options)

  • inputDirectory: src
  • outputDirectory: dist
  • configName: service-worker-config.js
  • scope: /
  • navigatorProperty: serviceWorkerConfig
  • prefetchRoot: true
  • prefetchResources: []
  • prefetchResourceGlobs: []
  • globOptions: {}
  • dryRun: false
  • disableEslint: {{NODE_ENV != production}}
  • verbose: {{NODE_ENV != production}}

Quickstart - Synchronize the Service Worker version

/* # Quickstart 
 *
 * The following synchronizes the `SW_VERSION` variable 
 * found in the `service-worker.js` file in the `src`
 * directory with the `version` number found in your
 * `package.json` file.
 */

const tools = require('sw-build-tools')

tools.syncVersion({
  versionVariableName: 'SW_VERSION',
  serviceWorkerDirectory: 'src'
})

/* **Example output in your Service Worker:**
 * 
 *   ```
 *   const SW_VERSION = 'x.y.z'
 *   // more code
 *   ```
 * 
 * # Why should you use this module?
 *
 * a) You are too lazy to manually update your Service 
 *    Worker version number
 *
 * b) You are so lazy that you haven't even tried Service 
 *    Worker yet, and you know you absolutely should
 */

API - tools.syncVersion(options)

  • version: {{package.json}}.version
  • versionVariableName: VERSION
  • versionVariableSingleQuotes: true
  • serviceWorkerDirectory: {{cwd}}
  • serviceWorkerFile: service-worker.js
  • dryRun: false
  • verbose: {{NODE_ENV != production}}

Todos

  • Add links to more resources about Service Workers
  • Create webpack plugin

License

WTFPL – Do What the F*ck You Want to Public License.

Made with :heart: by @MarkTiedemann.