Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parcel-plugin-precaching-sw

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parcel-plugin-precaching-sw

Parcel plugin that creates a precaching service worker

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Parcel plugin that creates a precaching serviceworker

The plugin is configurable by adding a precachingSW entry to your package.json file.

  "precachingSW": {
    "bypass": false,
    "allowed": [
      "js",
      "css",
      "map",
      "html"
    ],
    "additional": [],
    "offlineUrl": "/offline.html",
    "fileName": "sw.js",
    "outDir": "./"
  },
  • bypass → When set to true no serviceworker is created. Defaults to false.
  • allowed → Array of file extensions that will be added to the cache. Defaults an array containing the following extensions:
    • css
    • js
    • woff2
    • svg
    • ico
    • png
    • webmanifest
  • additional → Array containing additional files that must be added to the cache.
  • offlineUrl → Url of the offline html file, this file will be added to the cache as well.
  • fileName → The name of the file that holds the generated serviceworker. Defaults to sw.js.
  • outDir → The path to the directory where the serviceworker file will be saved to. Defaults to ./.

Example

In the example folder you'll find a very basic example of how to use and configure this plugin. To run the example cd into the example folder and run npm i. After all depedencies are installed run npm run start. Now parcels bundles the example app and after bundling it generates a serviceworker file. Then the app starts at localhost:1234.

In the package.json file you see that the plugin is added to the devDependencies. I am using file:.. here so the local version of the plugin will be installed; this is handy if you want to tinker a bit with the plugin code. In your real-life project it will look something like ^0.0.1.

Also in the package.json file you see the precachingSW entry; just play around with the parameters to get a grip on how they work.

The example project itself, and thus the project for which the plugin generates a precaching serverworker is fairly simple: it contains an index.html that embeds a stylesheet (app.css) and a javascript file (app.js). In the stylesheet a background image is applied to the body; because the jpeg extension is in the allowed array, you can see in the generated serviceworker file that the background image gets cached as well.

Background image from: https://www.pexels.com/

Keywords

FAQs

Package last updated on 15 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc