cloudcmd icon indicating copy to clipboard operation
cloudcmd copied to clipboard

chore(service-worker) migrate to service-worker-webpack

Open tatethurston opened this issue 2 years ago • 8 comments

Following up on https://github.com/tatethurston/service-worker-webpack/issues/1

  • [X] commit message named according to Contributing Guide
  • [ ] npm run codestyle is OK
  • [ ] npm test is OK

tatethurston avatar Apr 04 '23 22:04 tatethurston

Nice, thank you! Have you checked if it's working?

coderaiser avatar Apr 06 '23 12:04 coderaiser

I have next error:

image

coderaiser avatar Dec 05 '23 10:12 coderaiser

I have a service worker file I want to register

 entry: join(__dirname, '..', 'client', 'sw', 'sw.js'),

You just remove it, how should it be handled as service worker?

coderaiser avatar Dec 05 '23 10:12 coderaiser

I have a service worker file I want to register

 entry: join(__dirname, '..', 'client', 'sw', 'sw.js'),

You just remove it, how should it be handled as service worker?

If you take a look at the new dependency, you’ll see that it generates the service worker using workbox, rather than registering a custom service worker that you author.

tatethurston avatar Dec 05 '23 21:12 tatethurston

But I have a custom service worker and need it to work with webpack v5

coderaiser avatar Dec 06 '23 06:12 coderaiser

But I have a custom service worker and need it to work with webpack v5

Do you need a custom service worker? The last time I looked the generated service worker covered your use cases.

Tell me more about the webpack 5 concern?

tatethurston avatar Dec 06 '23 18:12 tatethurston

I want to migrate to rspack, it can be faster, and it supports only webpack 5. About custom service worker file, it caches files but next requests are excluded:

    if (url.endsWith('/') || /\^\/fs/.test(pathname))
        return;
    
    if (!isGet(request))
        return;
    
    if (!isBasic(request))
        return;
    
    if (pathname.startsWith('/api'))
        return;
    
    if (/^socket.io/.test(pathname))
        return;

coderaiser avatar Dec 06 '23 19:12 coderaiser

I want to migrate to rspack, it can be faster, and it supports only webpack 5. About custom service worker file, it caches files but next requests are excluded:

    if (url.endsWith('/') || /\^\/fs/.test(pathname))
        return;
    
    if (!isGet(request))
        return;
    
    if (!isBasic(request))
        return;
    
    if (pathname.startsWith('/api'))
        return;
    
    if (/^socket.io/.test(pathname))
        return;

I want to migrate to rspack, it can be faster, and it supports only webpack 5. About custom service worker file, it caches files but next requests are excluded:

    if (url.endsWith('/') || /\^\/fs/.test(pathname))
        return;
    
    if (!isGet(request))
        return;
    
    if (!isBasic(request))
        return;
    
    if (pathname.startsWith('/api'))
        return;
    
    if (/^socket.io/.test(pathname))
        return;

You can do excludes like this by configuring workbox. This is referenced in service-worker-webpack's documentation. An example can also be seen here. Alternatively, you can use https://www.npmjs.com/package/next-service-worker which wraps service-worker-webpack with excludes for nextjs.

Unfortunately I don't have bandwidth to assist with this further, so feel free to close this PR if you'd like to pursue another option.

tatethurston avatar Dec 06 '23 23:12 tatethurston