All Projects → cansin → next-with-workbox

cansin / next-with-workbox

Licence: MIT license
Higher order Next.js config to generate service workers

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to next-with-workbox

jekyll-pwa-workbox
A Jekyll plugin using Workbox to make your PWA / Website available offline.
Stars: ✭ 22 (+0%)
Mutual labels:  service-worker, progressive-web-app, workbox
Pwatter
Angular Progressive Web App using Workbox
Stars: ✭ 167 (+659.09%)
Mutual labels:  service-worker, progressive-web-app, workbox
So Pwa
A progressive web app to read Stack Overflow content.
Stars: ✭ 235 (+968.18%)
Mutual labels:  service-worker, progressive-web-app, workbox
Parcel Plugin Sw Cache
📦👷 Parcel plugin for caching using a service worker
Stars: ✭ 45 (+104.55%)
Mutual labels:  service-worker, progressive-web-app, workbox
react-app-rewire-workbox
Customise the service worker for create-react-app apps without ejecting - using Google's Workbox webpack plugins instead of the old sw-precache
Stars: ✭ 44 (+100%)
Mutual labels:  service-worker, progressive-web-app, workbox
chicio.github.io
👻 Fabrizio Duroni (me 😄) personal website. Created using GatsbyJS, Styled Components, Storybook, Typescript, tsParticles, GitHub pages, Github Actions, Upptime.
Stars: ✭ 20 (-9.09%)
Mutual labels:  service-worker, progressive-web-app, workbox
Pwa
Progressive Web Apps for Rails
Stars: ✭ 133 (+504.55%)
Mutual labels:  service-worker, progressive-web-app
Monitaure
🔔 A server uptime monitoring progressive web application - NO LONGER MAINTAINED
Stars: ✭ 135 (+513.64%)
Mutual labels:  service-worker, progressive-web-app
Generator Jekyll Starter Kit
🚀 Jekyll Progressive Web App Generator.
Stars: ✭ 139 (+531.82%)
Mutual labels:  service-worker, progressive-web-app
Progressive Weather App
A local weather app that fetches weather forecast from Openweathermap.org. A Progressive Web App built with Vue.js.
Stars: ✭ 223 (+913.64%)
Mutual labels:  service-worker, progressive-web-app
speedy-math
An application which allows user (small kids) to practice basic Mathematics operations
Stars: ✭ 28 (+27.27%)
Mutual labels:  progressive-web-app, workbox
affilicats
🐈 Progressive Web App demo that showcases flaky network resilience measures (📶 or 🚫📶).
Stars: ✭ 65 (+195.45%)
Mutual labels:  service-worker, progressive-web-app
Service Worker Detector
This extension detects if a website registers a Service Worker.
Stars: ✭ 124 (+463.64%)
Mutual labels:  service-worker, progressive-web-app
Workbox
📦 Workbox: JavaScript libraries for Progressive Web Apps
Stars: ✭ 10,434 (+47327.27%)
Mutual labels:  service-worker, progressive-web-app
Pwafire
Progressive Web Apps API of APIs
Stars: ✭ 137 (+522.73%)
Mutual labels:  service-worker, workbox
Notepad
📒 An offline capable Notepad PWA powered by ServiceWorker
Stars: ✭ 100 (+354.55%)
Mutual labels:  service-worker, progressive-web-app
Next Offline
make your Next.js application work offline using service workers via Google's workbox
Stars: ✭ 1,306 (+5836.36%)
Mutual labels:  service-worker, workbox
Productivity Frontend
Productivity Application - Kanban Style Productivity Management Application with Customizable Boards, Lists and Cards to Make You More Productive.
Stars: ✭ 234 (+963.64%)
Mutual labels:  service-worker, progressive-web-app
magento-meanbee-pwa
Progressive Web App extension for Magento 1
Stars: ✭ 75 (+240.91%)
Mutual labels:  service-worker, progressive-web-app
Ionic Pwa
🚀 Build a Progressive Web App with Ionic and Angular. Push Notifications. Deployed to Firebase Hosting. The Complete guide to build your PWA. Service Workers. Lighthouse. Web Manifest
Stars: ✭ 87 (+295.45%)
Mutual labels:  service-worker, progressive-web-app

next-with-workbox

tests codeql size dependencies downloads license

Higher order Next.js config to generate a Workbox service worker. It auto-magically sets up certain aspects like pre-caching public folder and cache busting exclusions in order to get the most out of Workbox with Next.js. Heavily inspired from shadowwalker/next-pwa.

Install

npm install next-with-workbox --save
# or
yarn add next-with-workbox

Basic Usage

Update or create next.config.js with

const withWorkbox = require("next-with-workbox");

module.exports = withWorkbox({
  workbox: {
    swSrc: "worker.js",
  },
  // .
  // ..
  // ... other Next.js config
});

Add public/sw.js and public/sw.js.map to your .gitignore

public/sw.js
public/sw.js.map

Create your service worker at /path/to/your-next-app/worker.js

import { precacheAndRoute } from "workbox-precaching";

precacheAndRoute(self.__WB_MANIFEST);

Register your service worker at /path/to/your-next-app/pages/_app.js:

import React, { useEffect } from "react";
import { Workbox } from "workbox-window";

function App({ Component, pageProps }) {
  useEffect(() => {
    if (
      !("serviceWorker" in navigator) ||
      process.env.NODE_ENV !== "production"
    ) {
      console.warn("Pwa support is disabled");
      return;
    }

    const wb = new Workbox("sw.js", { scope: "/" });
    wb.register();
  }, []);

  return <Component {...pageProps} />;
}

export default App;

Configuration

There are options you can use to customize the behavior of this plugin by adding workbox object in the Next.js config in next.config.js. Alongside those documented workbox options below, this library would also pass through any Workbox plugin options to the appropriate plugin

const withWorkbox = require("next-with-workbox");

module.exports = withWorkbox({
  workbox: {
    dest: "public",
    swDest: "sw.js",
    swSrc: "worker.js",
    force: true,
  },
});

Available Options

  • dest: string - the destination folder to put generated files, relative to the project root.
    • defaults to public.
  • swDest: string - the destination file to write the service worker code to.
    • defaults to sw.js.
  • swSrc: string - the input file to read the custom service worker code from. Setting this switches to InjectManifest plugin. If not set, GenerateSW plugin is used.
    • defaults to false.
  • force: boolean - whether to force enable Workbox in dev mode.
    • defaults to false.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].