Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tatethurston
Copy link

@tatethurston tatethurston commented Apr 4, 2023

Following up on tatethurston/service-worker-webpack#1

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

@coderaiser
Copy link
Owner

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

@coderaiser
Copy link
Owner

I have next error:

image

@coderaiser
Copy link
Owner

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?

@tatethurston
Copy link
Author

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.

@coderaiser
Copy link
Owner

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

@tatethurston
Copy link
Author

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?

@coderaiser
Copy link
Owner

coderaiser commented Dec 6, 2023

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;

@tatethurston
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants