serwist

A Swiss Army knife for service workers.

MIT License

Downloads
1.7M
Stars
667
Committers
81

Bot releases are visible (Hide)

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

  • bd75087 Thanks @DuCanhGH! - fix(cjs): fixed CommonJS builds crashing

    • Turns out we also need chunkFileNames, otherwise Rollup would always use ".js" for all the chunks. What in the world.
serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Minor Changes

  • b80b988 Thanks @DuCanhGH! - feat(vite): added @serwist/vite

    • This is a fork of vite-plugin-pwa, but it has undergone a major refactor so as to meet our use case. One can notice the obvious lack of features in comparison to vite-plugin-pwa.

    • At the moment, only base Vite and SvelteKit are supported. Support for some other frameworks, such as Astro, Nuxt, and Solid.js, will land soon.

    • Currently, @serwist/vite and its SvelteKit integration do not support development mode. This is because of two reasons:

      • vite-plugin-pwa's way of supporting dev was... seemingly unnecessarily bloated in my opinion. I hold the belief that having a separate "dev-sw.js" is not the way to go. Rather, I want to directly bundle swSrc. It's just that I've not figured out a way to do so. If that's not possible, perhaps we can consider their way of doing it again.
      • Many browsers still do not support using ESM in service workers, causing them to fail to parse SvelteKit's dev "service-worker.ts".
    • To get started:

      • Normal Vite:
      // src/sw.ts
      import type { PrecacheEntry } from "@serwist/precaching";
      import { installSerwist } from "@serwist/sw";
      import { defaultCache } from "@serwist/vite/worker";
      
      declare const self: ServiceWorkerGlobalScope & {
        // Change this attribute's name to your `injectionPoint`.
        __SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
      };
      
      installSerwist({
        precacheEntries: self.__SW_MANIFEST,
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        runtimeCaching: defaultCache,
      });
      
      // vite.config.{ts,js}
      import { serwist } from "@serwist/vite";
      import { defineConfig } from "vite";
      
      // https://vitejs.dev/config/
      export default defineConfig({
        plugins: [
          // other plugins...
          serwist({
            swSrc: "src/sw.ts",
            swDest: "sw.js",
            globDirectory: "dist",
            injectionPoint: "self.__SW_MANIFEST",
            rollupFormat: "iife",
          }),
        ],
      });
      
      // App.ts
      const registerSerwist = async () => {
        // dev mode is not supported at the moment.
        if (import.meta.env.DEV) return;
        const serwist = await getSerwist();
        if (serwist) {
          serwist.addEventListener("installed", () =>
            console.log("Serwist installed!"),
          );
          await serwist.register();
        }
      };
      registerSerwist();
      
      • SvelteKit:
      // src/service-worker.ts
      /// <reference no-default-lib="true"/>
      /// <reference lib="esnext" />
      /// <reference lib="webworker" />
      /// <reference types="@sveltejs/kit" />
      import type { PrecacheEntry } from "@serwist/precaching";
      import { installSerwist } from "@serwist/sw";
      import { defaultCache } from "@serwist/vite/worker";
      
      declare const self: ServiceWorkerGlobalScope & {
        // Change this attribute's name to your `injectionPoint`.
        __SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
      };
      
      installSerwist({
        precacheEntries: self.__SW_MANIFEST,
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        runtimeCaching: defaultCache,
      });
      
      // vite.config.{ts,js}
      import { serwist } from "@serwist/vite/integration-svelte";
      import { sveltekit } from "@sveltejs/kit/vite";
      import { defineConfig } from "vite";
      
      export default defineConfig({
        plugins: [
          sveltekit(),
          serwist({
            // dev mode is not supported at the moment.
            disable: process.env.NODE_ENV === "development",
          }),
        ],
      });
      
      // +layout.svelte
      $effect(() => {
        const registerSerwist = async () => {
          // dev mode is not supported at the moment.
          if (import.meta.env.DEV) return;
          const serwist = await getSerwist();
          if (serwist) {
            serwist.addEventListener("installed", () =>
              console.log("Serwist installed!"),
            );
            await serwist.register();
          }
        };
        registerSerwist();
      });
      

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 10 months ago

Patch Changes

Package Rankings
Top 23.13% on Npmjs.org