{"id":19374037,"url":"https://github.com/eolme/next-sw","last_synced_at":"2025-04-23T18:31:37.242Z","repository":{"id":65408076,"uuid":"466538892","full_name":"eolme/next-sw","owner":"eolme","description":"Use any service worker with nextjs","archived":false,"fork":false,"pushed_at":"2023-11-01T17:14:30.000Z","size":98,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T21:44:21.787Z","etag":null,"topics":["next","nextjs","service-worker","serviceworker","sw"],"latest_commit_sha":null,"homepage":"https://npm.im/next-sw","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eolme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-05T18:41:17.000Z","updated_at":"2023-10-16T04:04:52.000Z","dependencies_parsed_at":"2024-10-23T03:34:01.892Z","dependency_job_id":"4ed9032e-dc06-49d0-a2a7-5feef152d25e","html_url":"https://github.com/eolme/next-sw","commit_stats":{"total_commits":34,"total_committers":2,"mean_commits":17.0,"dds":0.02941176470588236,"last_synced_commit":"80c893b57b712f96af8dfb0a658cf357ec9252d8"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eolme%2Fnext-sw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eolme%2Fnext-sw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eolme%2Fnext-sw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eolme%2Fnext-sw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eolme","download_url":"https://codeload.github.com/eolme/next-sw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248602275,"owners_count":21131613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["next","nextjs","service-worker","serviceworker","sw"],"created_at":"2024-11-10T08:33:57.653Z","updated_at":"2025-04-23T18:31:36.940Z","avatar_url":"https://github.com/eolme.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-sw [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/eolme/next-sw/blob/master/LICENSE)\n\nUse **any** service worker with nextjs.\n\n## Features\n\n- Easy to use\n- No dependencies\n- No custom server needed\n- Supports `next export`\n\nAfter running `next` or `next build`, this will generate single file `sw.js` in your public folder, which serve statically.\n\nLive reloading and unregistering service worker are supported out of the box during development.\n\n## Configuration\n\nThere are options you can use to customize the behavior of this plugin in `next.config.js`:\n\n```js\nconst { withServiceWorker } = require('next-sw');\n\nmodule.exports = withServiceWorker({\n  name: 'sw.js',\n  entry: 'worker/entry.ts',\n  livereload: true\n})();\n```\n\n### Available Options\n\n- `name: string` - service worker name\n  - default to `sw.js`\n- `entry: string` - service worker script entry point\n- `livereload: boolean`\n  - default to `true` during development\n  - set `livereload: false` to disable live reloading\n  - note: if the option is disabled, you need to use your own implementation of page reload\n- `port: number`\n  - default to `4000`\n- `sideEffects: boolean | string | RegExp | string[] | RegExp[] | ((file: string) =\u003e boolean)`\n  - default to `true`\n- `resolve: boolean | 'force'` - patch resolve for worker support\n  - default to `false`\n  - set `'force'` to force patch\n\n## Usage\n\nYou need to manually register service worker, for example, in `pages/_app.jsx` like this:\n\n```js\nif (typeof window !== 'undefined') {\n  navigator.serviceWorker.register(process.env.__NEXT_SW, {\n    scope: process.env.__NEXT_SW_SCOPE\n  });\n}\n```\n\nor if you use `appDir`, you need to create a client component with registration:\n\n```js\n'use client';\n\nimport { useEffect } from 'react';\n\nexport const ClientServiceWorkerRegistration = () =\u003e {\n  useEffect(() =\u003e {\n    navigator.serviceWorker.register(process.env.__NEXT_SW, {\n      scope: process.env.__NEXT_SW_SCOPE\n    });\n  }, []);\n};\n```\n\nor create a universal one with check:\n\n```js\nimport { useEffect } from 'react';\n\nexport const ServiceWorkerRegistration = () =\u003e {\n  useEffect(() =\u003e {\n    if (typeof window !== 'undefined') {\n      navigator.serviceWorker.register(process.env.__NEXT_SW, {\n        scope: process.env.__NEXT_SW_SCOPE\n      });\n    }\n  }, []);\n};\n```\n\n## Installation\n\nRecommend to use [yarn](https://yarnpkg.com/getting-started/install) for dependency management:\n\n```shell\nyarn add -D next-sw\n```\n\n## License\n\nnext-sw is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feolme%2Fnext-sw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feolme%2Fnext-sw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feolme%2Fnext-sw/lists"}