chore: use hi@ayo.run email
Some checks failed
Demo / Explore-CI (push) Has been cancelled

This commit is contained in:
ayo 2026-03-29 18:52:49 +02:00
parent 3022269826
commit c8424c53a0

View file

@ -16,9 +16,10 @@ This integration was originally developed to support the Caching strategy needs
There is a work in progress adding `presets` for using common caching strategies and customizing the behavior of the service worker via config options. This aims to reduce the need for writing the service worker script by hand for most use cases. There is a work in progress adding `presets` for using common caching strategies and customizing the behavior of the service worker via config options. This aims to reduce the need for writing the service worker script by hand for most use cases.
Get in touch: Get in touch:
1. Submit tickets via [SourceHut todo](https://todo.sr.ht/~ayoayco/astro-sw) 1. Submit tickets via [SourceHut todo](https://todo.sr.ht/~ayoayco/astro-sw)
1. Start a [GitHub discussion](https://github.com/ayoayco/astro-sw/discussions) 1. Start a [GitHub discussion](https://github.com/ayoayco/astro-sw/discussions)
1. Email me: [ayo@ayco.io](mailto:ayo@ayco.io) 1. Email me: [hi@ayo.run](mailto:hi@ayo.run)
## Installation ## Installation
@ -37,16 +38,16 @@ $ pnpm add @ayco/astro-sw
Here's an example `astro.config.mjs` file: Here's an example `astro.config.mjs` file:
```js ```js
import { defineConfig } from "astro/config"; import { defineConfig } from 'astro/config'
import serviceWorker from "@ayco/astro-sw"; import serviceWorker from '@ayco/astro-sw'
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
serviceWorker({ serviceWorker({
path: "./src/sw.ts", path: './src/sw.ts',
}), }),
], ],
}); })
``` ```
For more options available, see the [API](#api). For more options available, see the [API](#api).
@ -56,19 +57,19 @@ For more options available, see the [API](#api).
We use `esbuild` to resolve service worker `imports` and build TS files! You can customize the build options by providing it to the `esbuild` configuration property. We use `esbuild` to resolve service worker `imports` and build TS files! You can customize the build options by providing it to the `esbuild` configuration property.
```js ```js
import { defineConfig } from "astro/config"; import { defineConfig } from 'astro/config'
import serviceWorker from "@ayco/astro-sw"; import serviceWorker from '@ayco/astro-sw'
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
serviceWorker({ serviceWorker({
path: "./src/sw.ts", path: './src/sw.ts',
esbuild: { esbuild: {
minify: true, minify: true,
}, },
}), }),
], ],
}); })
``` ```
## Injected variables ## Injected variables
@ -80,7 +81,7 @@ The most important variable your service worker will have access to is `__assets
Because of the injected variables not being defined in your script, you might get `eslint` errors for the undefined variables when you have the `no-undef` rule. To prevent this, you can use our exported `globals` object in your eslint config as follows: Because of the injected variables not being defined in your script, you might get `eslint` errors for the undefined variables when you have the `no-undef` rule. To prevent this, you can use our exported `globals` object in your eslint config as follows:
```js ```js
import astroSwGlobals from "@ayco/astro-sw/globals"; import astroSwGlobals from '@ayco/astro-sw/globals'
export default [ export default [
{ {
@ -92,7 +93,7 @@ export default [
}, },
// add more generic rule sets here, such as: // add more generic rule sets here, such as:
// jsPlugin.configs.recommended, // jsPlugin.configs.recommended,
]; ]
``` ```
## Registration Hooks ## Registration Hooks
@ -109,27 +110,27 @@ The following properties are available for the `registrationHooks` configuration
1. `afterRegistration` - after the registration succeeds 1. `afterRegistration` - after the registration succeeds
```js ```js
import { defineConfig } from "astro/config"; import { defineConfig } from 'astro/config'
import serviceWorker from "@ayco/astro-sw"; import serviceWorker from '@ayco/astro-sw'
export default defineConfig({ export default defineConfig({
integrations: [ integrations: [
serviceWorker({ serviceWorker({
path: "./src/sw.ts", path: './src/sw.ts',
registrationHooks: { registrationHooks: {
afterRegistration: async () => { afterRegistration: async () => {
const sw = await navigator.serviceWorker.getRegistration(); const sw = await navigator.serviceWorker.getRegistration()
console.log(">>> registrered", sw); console.log('>>> registrered', sw)
}, },
installing: () => console.log("installing..."), installing: () => console.log('installing...'),
waiting: () => console.log("waiting..."), waiting: () => console.log('waiting...'),
active: () => console.log("active..."), active: () => console.log('active...'),
error: (error) => console.error(error), error: (error) => console.error(error),
unsupported: () => console.log(":("), unsupported: () => console.log(':('),
}, },
}), }),
], ],
}); })
``` ```
## API ## API