Giter Club home page Giter Club logo

parcel-plugin-workbox-cache's Introduction

parcel-plugin-workbox-cache

NPM npm npm GitHub stars GitHub watchers GitHub forks

An updated plugin for Parcel to generate a service worker with Workbox, derived from Anders Dahnielson's parcel-plugin-workbox.

Install

You can either install by running yarn (recommended)

yarn add parcel-plugin-workbox-cache --dev

or use npm

npm install parcel-plugin-workbox-cache --save-dev

Usage

When you build resources with Parcel, the plugin will generate a service worker sw.js and insert it into your project's index.html entry file.

You can customize the settings by adding a .workbox-config.js file in the root of your project. This will be the settings that will be passed to generateSW()function found in workbox-build dependency. If you don't create any config file, default settings will be passed:

    {
      importScripts: ['./worker.js'],
      globDirectory: './dist'
      globPatterns: [`**/*.{css,html,js,gif,ico,jpg,png,svg,webp,woff,woff2,ttf,otf}`]
    }

Here's an example .workbox-config.js file

module.exports = {
  importScripts: [],
  globDirectory: "./dist",
  globPatterns: [
    "**/*.{css,html,js,gif,ico,jpg,png,svg,webp,woff,woff2,ttf,otf,eot,webmanifest,manifest}"
  ],
  runtimeCaching: [
    {
      urlPattern: new RegExp("^https:\/\/firebasestorage\\.googleapis\\.com\/.*", "gi"),
      handler: "CacheFirst",
      options: {
        cacheableResponse: {
          statuses: [0, 200]
        },
        cacheName: "images"
      }
    }
  ],
  offlineGoogleAnalytics: true
};

By default, a worker.js file, where you can write the logic for your service worker, will be read from your project's root directory and imported into sw.js unless you change this setting. Additionally, a CDN version of Google Workbox is imported automatically.

Note: If you have this plugin active during development, you will need to either disable or manually delete the service worker to bypass caching.

parcel-plugin-workbox-cache's People

Contributors

lexich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.