Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/makkarpov/nuxt-service-worker
Module to bundle your custom service worker code in Nuxt
https://github.com/makkarpov/nuxt-service-worker
Last synced: 6 days ago
JSON representation
Module to bundle your custom service worker code in Nuxt
- Host: GitHub
- URL: https://github.com/makkarpov/nuxt-service-worker
- Owner: makkarpov
- License: mit
- Created: 2022-07-07T21:25:21.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-25T11:18:53.000Z (over 1 year ago)
- Last Synced: 2024-10-22T13:31:31.544Z (15 days ago)
- Language: TypeScript
- Size: 177 KB
- Stars: 8
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nuxt-service-worker
Simple module that configures build system to bundle and expose service worker script at website root path.
Targets at and supports only Vite/Rollup tooling.
## Usage:
Install this package:
```
npm install --save-dev @makkarpov/nuxt-service-worker
```Configure worker script entry point in your Nuxt configuration, e.g.:
```ts
export default defineNuxtConfig({
modules: [
'@makkarpov/nuxt-service-worker'
],
serviceWorker: {
entryPoint: 'lib/worker.ts'
}
});
```Use special synthetic import to get information about worker script location:
```ts
import worker from '#service-worker';
await navigator.serviceWorker.register(worker.url, { type: 'module' });
```When running in dev mode, service worker script will be available as `/sw.js` file. During production build worker script will be chunked and packaged just as everything else, resulting in `/sw-XXXXXXXX.mjs` file lying in your `.output/public` dir.
## Development
- Run `npm run dev:prepare` to generate type stubs.
- Use `npm run dev` to start playground in development mode.
- Use `npm run dev:build` and `npm run dev:preview` to test production build.