Vite injects empty array into service-worker (self.__WB_MANIFEST)

57 views Asked by At

I'm trying to setup precaching with VitePWA. The service worker registers fine, but VitePWA injects an empty array into the file so no assets are being cached.

I have no clue as to why that's a case and can't find any issues on google / github.

I suppose I'm configuring it wrong.

This is the vite config:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';
import viteCompression from 'vite-plugin-compression';
import svgr from 'vite-plugin-svgr';

export default defineConfig({
  envPrefix: 'REACT_APP_',
  plugins: [
    svgr(),
    react(),
    VitePWA({
      workbox: {
        globPatterns: ['**/*.{js,css,html}'],
      },
      srcDir: 'src',
      filename: 'service-worker.js',
      strategies: 'injectManifest',
      injectRegister: false,
      devOptions: {
        enabled: true,
        type: 'module',
      },
    }),
    viteCompression(),
  ],
});

And this is part of the service-worker

import { precacheAndRoute } from 'workbox-precaching';
import { clientsClaim } from 'workbox-core';

self.skipWaiting();
clientsClaim();
precacheAndRoute(self.__WB_MANIFEST); //<-- Will be inlined to []

How can I configure VitePWA to include all assets in the /public directory?

0

There are 0 answers