@unplugin-pwa/core 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/client.d.ts +6 -0
- package/info.d.ts +71 -0
- package/package.json +133 -7
- package/preact.d.ts +17 -0
- package/pwa-assets.d.ts +40 -0
- package/react-legacy.d.ts +22 -0
- package/react.d.ts +17 -0
- package/solid.d.ts +17 -0
- package/svelte.d.ts +17 -0
- package/types/index.d.ts +43 -0
- package/types/package.json +3 -0
- package/vanillajs.d.ts +13 -0
- package/vue.d.ts +17 -0
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-PRESENT Anthony Fu <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
<p align='center'>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/vite-pwa/.github/main/unplugin-pwa-core-hero-dark.svg" />
|
|
4
|
+
<img src="https://raw.githubusercontent.com/vite-pwa/.github/main/unplugin-pwa-core-hero.svg" alt="Bundler-agnostic core logic and utilities for PWA logo">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
<h1 align="center">Bundler-agnostic core logic and utilities for PWA</h1>
|
|
9
|
+
|
|
10
|
+
<p align='center'>
|
|
11
|
+
<a href='https://npmx.dev/package/@unplugin-pwa/core' target="_blank" rel="noopener noreferrer">
|
|
12
|
+
<img src='https://img.shields.io/npm/v/@unplugin-pwa/core?color=33A6B8&label=' alt="NPM version">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://npmx.dev/package/@unplugin-pwa/core" target="_blank" rel="noopener noreferrer">
|
|
15
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/dm/@unplugin-pwa/core?color=476582&label=">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://unplugin-pwa.netlify.app/unplugin-pwa/core.html" target="_blank" rel="noopener noreferrer">
|
|
18
|
+
<img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20guides&color=2e859c" alt="Docs & Guides">
|
|
19
|
+
</a>
|
|
20
|
+
<br>
|
|
21
|
+
<a href="https://github.com/vite-pwa/unplugin-pwa" target="_blank" rel="noopener noreferrer">
|
|
22
|
+
<img alt="GitHub stars" src="https://img.shields.io/github/stars/vite-pwa/unplugin-pwa?style=social">
|
|
23
|
+
</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<br>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
30
|
+
<img src="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg" alt="Anthony Fu SVG sponsors image" />
|
|
31
|
+
</a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
## 🧱 What is `@unplugin-pwa/core`?
|
|
35
|
+
|
|
36
|
+
The bundler-agnostic foundation of `unplugin-pwa`. It contains the shared PWA logic (configuration resolution, Web App Manifest, service worker registration, virtual modules, PWA assets and inspector utilities) with no dependency on any specific bundler.
|
|
37
|
+
|
|
38
|
+
> 💡 **Note:** this package is aimed at integration authors. If you just want to add PWA support to your app, use an integration such as [`@unplugin-pwa/vite`](https://npmx.dev/package/@unplugin-pwa/vite) instead.
|
|
39
|
+
|
|
40
|
+
## 🧩 What's inside?
|
|
41
|
+
|
|
42
|
+
Each area is exposed as its own subpath export, so you only import what you need and everything stays tree-shakable.
|
|
43
|
+
|
|
44
|
+
| Area | Subpaths |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Configuration and context | `config`, `context`, `context-types`, `constants`, `prepare-pwa-context`, `prepare-sw-names` |
|
|
47
|
+
| Web App Manifest | `generate-web-manifest`, `create-web-manifest-html-link`, `inject-web-manifest-html-link` |
|
|
48
|
+
| Service worker registration | `generate-register-sw`, `create-generate-register-sw-script`, `inject-generate-register-sw`, `generate-virtual-module` |
|
|
49
|
+
| Service worker utilities | `additional-manifest-entries`, `dual-sw-utilities`, `build-pwa-asset` |
|
|
50
|
+
| Development | `dev/prepare-sw-names-and-glob-directory`, `dev/prepare-temp-folder` |
|
|
51
|
+
| PWA Assets | `pwa-assets/*` (`build`, `config`, `dev`, `generator`, `html`, `manifest`, `options`, `types`, `utils`) |
|
|
52
|
+
| Inspector | `inspector-utils`, `resolve-inspector-dist` |
|
|
53
|
+
| Misc | `html`, `helpers`, `logs` |
|
|
54
|
+
|
|
55
|
+
## 🏷️ Client types
|
|
56
|
+
|
|
57
|
+
The virtual module and framework type declarations also live here, shared by all integrations:
|
|
58
|
+
|
|
59
|
+
| Subpath | Use it for |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `@unplugin-pwa/core/client` | Virtual modules (base) |
|
|
62
|
+
| `@unplugin-pwa/core/vanillajs` | Vanilla JavaScript |
|
|
63
|
+
| `@unplugin-pwa/core/vue` | Vue 3 |
|
|
64
|
+
| `@unplugin-pwa/core/react` | React |
|
|
65
|
+
| `@unplugin-pwa/core/react-legacy` | React (legacy) |
|
|
66
|
+
| `@unplugin-pwa/core/preact` | Preact |
|
|
67
|
+
| `@unplugin-pwa/core/solid` | SolidJS |
|
|
68
|
+
| `@unplugin-pwa/core/svelte` | Svelte |
|
|
69
|
+
| `@unplugin-pwa/core/info` | `virtual:pwa-info` |
|
|
70
|
+
| `@unplugin-pwa/core/pwa-assets` | PWA Assets virtual modules |
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"compilerOptions": {
|
|
75
|
+
"types": ["@unplugin-pwa/core/vue"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 📋 Requirements
|
|
81
|
+
|
|
82
|
+
`@unplugin-pwa/core` requires **Node 22.14.0 or above**.
|
|
83
|
+
|
|
84
|
+
The following peer dependencies are all optional; install them only if your integration needs them:
|
|
85
|
+
|
|
86
|
+
- `vite`: from 3.1 to 8.
|
|
87
|
+
- `rolldown`: 1.0.0 or above.
|
|
88
|
+
- `@vite-pwa/assets-generator`: 1.x or 2.x, only when using PWA Assets.
|
|
89
|
+
|
|
90
|
+
## 📦 Install
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm i -D @unplugin-pwa/core
|
|
94
|
+
|
|
95
|
+
# yarn
|
|
96
|
+
yarn add -D @unplugin-pwa/core
|
|
97
|
+
|
|
98
|
+
# pnpm
|
|
99
|
+
pnpm add -D @unplugin-pwa/core
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 📄 License
|
|
103
|
+
|
|
104
|
+
[MIT](./LICENSE) License © 2026-PRESENT [Anthony Fu](https://github.com/antfu)
|
package/client.d.ts
ADDED
package/info.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
declare module 'virtual:pwa-info' {
|
|
2
|
+
export interface PwaInfo {
|
|
3
|
+
pwaInDevEnvironment: boolean
|
|
4
|
+
/**
|
|
5
|
+
* The web manifest will be always here.
|
|
6
|
+
*/
|
|
7
|
+
webManifest: {
|
|
8
|
+
href: string
|
|
9
|
+
useCredentials: boolean
|
|
10
|
+
/**
|
|
11
|
+
* The link tag with or without `crossorigin`:
|
|
12
|
+
* - `<link rel="manifest" href="<webManifestUrl>" />`.
|
|
13
|
+
* - `<link rel="manifest" href="<webManifestUrl>" crossorigin="use-credentials" />`.
|
|
14
|
+
*/
|
|
15
|
+
linkTag: string
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The service worker data will be exposed only if required, that's, will **NOT** be exposed if:
|
|
19
|
+
* - not using `pwaPluginOptions.injectRegister` with `script`, `script-defer` or `inline` values
|
|
20
|
+
* - if using `pwaPluginOptions.injectRegister` with `auto` (default) and importing any of the virtual modules
|
|
21
|
+
*
|
|
22
|
+
* **NOTE**: `registerSW` will be `undefined` if:
|
|
23
|
+
* - SSR build (only if required)
|
|
24
|
+
* - PWA is disabled: `pwaPluginOptions.disable = true`
|
|
25
|
+
* - running `Dev Server` and `pwaPluginOptions.devOptions.enabled = false` (default).
|
|
26
|
+
*/
|
|
27
|
+
registerSW?: {
|
|
28
|
+
/**
|
|
29
|
+
* Should use `type="module"?
|
|
30
|
+
*
|
|
31
|
+
* **NOTE**: `module` will be `true` **ONLY** at `Dev server` and using dual service worker workers: `classic-and-module`.
|
|
32
|
+
*/
|
|
33
|
+
module: boolean
|
|
34
|
+
/**
|
|
35
|
+
* When this flag is `inline` the service worker must be registered via inline script otherwise registered via script with src attribute `registerSW.js`.
|
|
36
|
+
*/
|
|
37
|
+
mode: 'inline' | 'script' | 'script-defer'
|
|
38
|
+
/**
|
|
39
|
+
* The path for the inline script: will contain the service worker url.
|
|
40
|
+
*/
|
|
41
|
+
inlinePath: string
|
|
42
|
+
/**
|
|
43
|
+
* The path for the src script for `registerSW.js`.
|
|
44
|
+
*/
|
|
45
|
+
registerPath: string
|
|
46
|
+
/**
|
|
47
|
+
* The scope for the service worker: only required for `inline: true`.
|
|
48
|
+
*/
|
|
49
|
+
scope: string
|
|
50
|
+
/**
|
|
51
|
+
* The type for the service worker: only required for `inline: true`.
|
|
52
|
+
*/
|
|
53
|
+
type: 'classic' | 'module'
|
|
54
|
+
/**
|
|
55
|
+
* The script tag if `shouldRegisterSW` returns `true`.
|
|
56
|
+
*/
|
|
57
|
+
scriptTag?: string
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Return the PWA information if available.
|
|
62
|
+
*
|
|
63
|
+
* This property will be `undefined` if:
|
|
64
|
+
* - SSR build
|
|
65
|
+
* - PWA is disabled: `pwaPluginOptions.disable = true`
|
|
66
|
+
* - running `Dev Server` and `pwaPluginOptions.devOptions.enabled = false` (default).
|
|
67
|
+
*
|
|
68
|
+
* @returns The PWA information.
|
|
69
|
+
*/
|
|
70
|
+
export const pwaInfo: PwaInfo | undefined
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unplugin-pwa/core",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
5
|
"description": "PWA bundler-agnostic core logic and utilities",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
6
|
"author": "Vite PWA's Team",
|
|
7
|
+
"maintainers": [
|
|
8
|
+
"userquin <userquin@gmail.com>"
|
|
9
|
+
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"funding": "https://github.com/sponsors/antfu",
|
|
11
12
|
"homepage": "https://github.com/vite-pwa/unplugin-pwa#readme",
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
|
@@ -25,5 +26,130 @@
|
|
|
25
26
|
"agnostic",
|
|
26
27
|
"configuration",
|
|
27
28
|
"helpers"
|
|
28
|
-
]
|
|
29
|
-
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.mts"
|
|
34
|
+
},
|
|
35
|
+
"./additional-manifest-entries": "./dist/additional-manifest-entries.mjs",
|
|
36
|
+
"./build-pwa-asset": "./dist/build-pwa-asset.mjs",
|
|
37
|
+
"./config": "./dist/config.mjs",
|
|
38
|
+
"./constants": "./dist/constants.mjs",
|
|
39
|
+
"./context": "./dist/context.mjs",
|
|
40
|
+
"./context-types": {
|
|
41
|
+
"types": "./dist/context-types.d.mts"
|
|
42
|
+
},
|
|
43
|
+
"./create-generate-register-sw-script": "./dist/create-generate-register-sw-script.mjs",
|
|
44
|
+
"./create-web-manifest-html-link": "./dist/create-web-manifest-html-link.mjs",
|
|
45
|
+
"./dual-sw-utilities": "./dist/dual-sw-utilities.mjs",
|
|
46
|
+
"./generate-register-sw": "./dist/generate-register-sw.mjs",
|
|
47
|
+
"./generate-web-manifest": "./dist/generate-web-manifest.mjs",
|
|
48
|
+
"./html": "./dist/html.mjs",
|
|
49
|
+
"./helpers": "./dist/helpers.mjs",
|
|
50
|
+
"./inject-generate-register-sw": "./dist/inject-generate-register-sw.mjs",
|
|
51
|
+
"./inject-web-manifest-html-link": "./dist/inject-web-manifest-html-link.mjs",
|
|
52
|
+
"./inspector-utils": "./dist/inspector-utils.mjs",
|
|
53
|
+
"./logs": "./dist/logs.mjs",
|
|
54
|
+
"./prepare-pwa-context": "./dist/prepare-pwa-context.mjs",
|
|
55
|
+
"./prepare-sw-names": "./dist/prepare-sw-names.mjs",
|
|
56
|
+
"./resolve-inspector-dist": "./dist/resolve-inspector-dist.mjs",
|
|
57
|
+
"./dev/prepare-sw-names-and-glob-directory": "./dist/dev/prepare-sw-names-and-glob-directory.mjs",
|
|
58
|
+
"./dev/prepare-temp-folder": "./dist/dev/prepare-temp-folder.mjs",
|
|
59
|
+
"./pwa-assets/build": "./dist/pwa-assets/build.mjs",
|
|
60
|
+
"./pwa-assets/config": "./dist/pwa-assets/config.mjs",
|
|
61
|
+
"./pwa-assets/dev": "./dist/pwa-assets/dev.mjs",
|
|
62
|
+
"./pwa-assets/generator": "./dist/pwa-assets/generator.mjs",
|
|
63
|
+
"./pwa-assets/html": "./dist/pwa-assets/html.mjs",
|
|
64
|
+
"./pwa-assets/manifest": "./dist/pwa-assets/manifest.mjs",
|
|
65
|
+
"./pwa-assets/options": "./dist/pwa-assets/options.mjs",
|
|
66
|
+
"./pwa-assets/types": {
|
|
67
|
+
"types": "./dist/pwa-assets/types.d.mts"
|
|
68
|
+
},
|
|
69
|
+
"./pwa-assets/utils": "./dist/pwa-assets/utils.mjs",
|
|
70
|
+
"./types": {
|
|
71
|
+
"types": "./types/index.d.ts"
|
|
72
|
+
},
|
|
73
|
+
"./preact": {
|
|
74
|
+
"types": "./preact.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./react": {
|
|
77
|
+
"types": "./react.d.ts"
|
|
78
|
+
},
|
|
79
|
+
"./react-legacy": {
|
|
80
|
+
"types": "./react-legacy.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./solid": {
|
|
83
|
+
"types": "./solid.d.ts"
|
|
84
|
+
},
|
|
85
|
+
"./svelte": {
|
|
86
|
+
"types": "./svelte.d.ts"
|
|
87
|
+
},
|
|
88
|
+
"./vanillajs": {
|
|
89
|
+
"types": "./vanillajs.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./vue": {
|
|
92
|
+
"types": "./vue.d.ts"
|
|
93
|
+
},
|
|
94
|
+
"./client": {
|
|
95
|
+
"types": "./client.d.ts"
|
|
96
|
+
},
|
|
97
|
+
"./info": {
|
|
98
|
+
"types": "./info.d.ts"
|
|
99
|
+
},
|
|
100
|
+
"./pwa-assets": {
|
|
101
|
+
"types": "./pwa-assets.d.ts"
|
|
102
|
+
},
|
|
103
|
+
"./package.json": "./package.json"
|
|
104
|
+
},
|
|
105
|
+
"files": [
|
|
106
|
+
"*.d.ts",
|
|
107
|
+
"dist",
|
|
108
|
+
"types"
|
|
109
|
+
],
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">=22.14.0"
|
|
112
|
+
},
|
|
113
|
+
"peerDependencies": {
|
|
114
|
+
"@vite-pwa/assets-generator": "^1.0.0 || ^2.0.0",
|
|
115
|
+
"rolldown": "^1.0.0-0",
|
|
116
|
+
"vite": "^3.1.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
117
|
+
},
|
|
118
|
+
"peerDependenciesMeta": {
|
|
119
|
+
"@vite-pwa/assets-generator": {
|
|
120
|
+
"optional": true
|
|
121
|
+
},
|
|
122
|
+
"rolldown": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
125
|
+
"vite": {
|
|
126
|
+
"optional": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"dependencies": {
|
|
130
|
+
"@vite-pwa/workbox-build": "^8.0.13",
|
|
131
|
+
"hookable": "^6.1.2"
|
|
132
|
+
},
|
|
133
|
+
"devDependencies": {
|
|
134
|
+
"@types/react": "^19.3.0",
|
|
135
|
+
"@vite-pwa/assets-generator": "^2.0.0",
|
|
136
|
+
"preact": "^10.29.8",
|
|
137
|
+
"react": "^19.3.1",
|
|
138
|
+
"rolldown": "^1.2.14",
|
|
139
|
+
"solid-js": "^1.9.17",
|
|
140
|
+
"svelte": "^5.57.2",
|
|
141
|
+
"vite": "^8.3.5",
|
|
142
|
+
"vue": "^3.5.44"
|
|
143
|
+
},
|
|
144
|
+
"publishConfig": {
|
|
145
|
+
"access": "public",
|
|
146
|
+
"provenance": true
|
|
147
|
+
},
|
|
148
|
+
"scripts": {
|
|
149
|
+
"build": "tsdown --config-loader unrun",
|
|
150
|
+
"test:typecheck": "tsc --noEmit",
|
|
151
|
+
"test:ci": "vitest run --coverage",
|
|
152
|
+
"test": "vitest",
|
|
153
|
+
"test:ui": "vitest --ui --open --coverage"
|
|
154
|
+
}
|
|
155
|
+
}
|
package/preact.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/preact' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when preact/hooks is not installed
|
|
5
|
+
import type { Dispatch, StateUpdater } from 'preact/hooks'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [boolean, Dispatch<StateUpdater<boolean>>]
|
|
11
|
+
offlineReady: [boolean, Dispatch<StateUpdater<boolean>>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/pwa-assets.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* WARNING: these virtual modules are meant to be used by integrations and not being consumed directly from applications */
|
|
2
|
+
|
|
3
|
+
declare module 'virtual:pwa-assets/head' {
|
|
4
|
+
export interface PWAAssetHeadLink {
|
|
5
|
+
id?: string
|
|
6
|
+
rel: 'apple-touch-startup-image' | 'apple-touch-icon' | 'icon'
|
|
7
|
+
href: string
|
|
8
|
+
media?: string
|
|
9
|
+
sizes?: string
|
|
10
|
+
type?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ColorSchemeMeta {
|
|
14
|
+
name: string
|
|
15
|
+
content: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PWAAssetsHead {
|
|
19
|
+
links: PWAAssetHeadLink[]
|
|
20
|
+
themeColor?: ColorSchemeMeta
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const pwaAssetsHead: PWAAssetsHead
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module 'virtual:pwa-assets/icons' {
|
|
27
|
+
import type { AppleSplashScreenLink, FaviconLink, HtmlLink, IconAsset } from '@vite-pwa/assets-generator/api'
|
|
28
|
+
|
|
29
|
+
export type PWAAssetIcon<T extends HtmlLink> = Omit<IconAsset<T>, 'buffer'>
|
|
30
|
+
|
|
31
|
+
export interface PWAAssetsIcons {
|
|
32
|
+
favicon: Record<string, PWAAssetIcon<FaviconLink>>
|
|
33
|
+
transparent: Record<string, PWAAssetIcon<HtmlLink>>
|
|
34
|
+
maskable: Record<string, PWAAssetIcon<HtmlLink>>
|
|
35
|
+
apple: Record<string, PWAAssetIcon<HtmlLink>>
|
|
36
|
+
appleSplashScreen: Record<string, PWAAssetIcon<AppleSplashScreenLink>>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const pwaAssetsIcons: PWAAssetsIcons
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module is a legacy version of the PWA register hook for React and will
|
|
3
|
+
* be removed in the next major version.
|
|
4
|
+
* @deprecated use `virtual:pwa-register/react` instead
|
|
5
|
+
*/
|
|
6
|
+
declare module 'virtual:pwa-register/react-legacy' {
|
|
7
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
8
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
9
|
+
// @ts-ignore ignore when react is not installed
|
|
10
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
11
|
+
|
|
12
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
13
|
+
|
|
14
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
15
|
+
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
16
|
+
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
17
|
+
/**
|
|
18
|
+
* Reloads the current window to allow the service worker take the control.
|
|
19
|
+
*/
|
|
20
|
+
updateServiceWorker: () => Promise<void>
|
|
21
|
+
}
|
|
22
|
+
}
|
package/react.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/react' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when react is not installed
|
|
5
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
11
|
+
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/solid.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/solid' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when solid-js is not installed
|
|
5
|
+
import type { Accessor, Setter } from 'solid-js'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: [Accessor<boolean>, Setter<boolean>]
|
|
11
|
+
offlineReady: [Accessor<boolean>, Setter<boolean>]
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/svelte.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/svelte' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when svelte is not installed
|
|
5
|
+
import type { Writable } from 'svelte/store'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: Writable<boolean>
|
|
11
|
+
offlineReady: Writable<boolean>
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { TrustedScriptURL } from 'trusted-types/lib'
|
|
2
|
+
|
|
3
|
+
export type { TrustedScriptURL } from 'trusted-types/lib'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A function that returns the service worker trusted script url.
|
|
7
|
+
*
|
|
8
|
+
* @param classic Whether the browser is in legacy mode (i.e. not supporting ES modules in service workers).
|
|
9
|
+
* @param swUrl The url for the service worker.
|
|
10
|
+
* @returns The service worker script url.
|
|
11
|
+
*/
|
|
12
|
+
export type PWATrustedScriptURL = (classic: boolean, swUrl: string) => TrustedScriptURL
|
|
13
|
+
|
|
14
|
+
export interface RegisterSWOptions {
|
|
15
|
+
immediate?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* Called when the service worker has taken control and the page would normally reload.
|
|
18
|
+
*
|
|
19
|
+
* Useful to fully control the reload flow (for example, to defer reload until the next
|
|
20
|
+
* SPA navigation).
|
|
21
|
+
*/
|
|
22
|
+
onNeedReload?: () => void
|
|
23
|
+
onNeedRefresh?: () => void
|
|
24
|
+
onOfflineReady?: () => void
|
|
25
|
+
/**
|
|
26
|
+
* Service worker trusted script url.
|
|
27
|
+
*
|
|
28
|
+
* @since 2.0.0
|
|
29
|
+
*/
|
|
30
|
+
trustedScriptUrl?: TrustedScriptURL | PWATrustedScriptURL
|
|
31
|
+
/**
|
|
32
|
+
* Called once the service worker is registered (requires version `0.12.8+`).
|
|
33
|
+
*
|
|
34
|
+
* @param swScriptUrl The service worker script url.
|
|
35
|
+
* @param registration The service worker registration if available.
|
|
36
|
+
*/
|
|
37
|
+
onRegisteredSW?: (swScriptUrl: string, registration: ServiceWorkerRegistration | undefined) => void
|
|
38
|
+
onRegisterError?: (error: unknown) => void
|
|
39
|
+
/**
|
|
40
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/updateViaCache
|
|
41
|
+
*/
|
|
42
|
+
updateViaCache?: ServiceWorkerUpdateViaCache
|
|
43
|
+
}
|
package/vanillajs.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions } from '@unplugin-pwa/core/types'
|
|
3
|
+
|
|
4
|
+
export type { PWATrustedScriptURL, RegisterSWOptions }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers the service worker returning a callback to reload the current page when an update is found.
|
|
8
|
+
*
|
|
9
|
+
* @param options the options to register the service worker.
|
|
10
|
+
* @return The callback to activate the new service worker.
|
|
11
|
+
*/
|
|
12
|
+
export function registerSW(options?: RegisterSWOptions): () => Promise<void>
|
|
13
|
+
}
|
package/vue.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'virtual:pwa-register/vue' {
|
|
2
|
+
import type { PWATrustedScriptURL, RegisterSWOptions, TrustedScriptURL } from '@unplugin-pwa/core/types'
|
|
3
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
4
|
+
// @ts-ignore ignore when vue is not installed
|
|
5
|
+
import type { Ref } from 'vue'
|
|
6
|
+
|
|
7
|
+
export type { PWATrustedScriptURL, RegisterSWOptions, TrustedScriptURL }
|
|
8
|
+
|
|
9
|
+
export function useRegisterSW(options?: RegisterSWOptions): {
|
|
10
|
+
needRefresh: Ref<boolean>
|
|
11
|
+
offlineReady: Ref<boolean>
|
|
12
|
+
/**
|
|
13
|
+
* Reloads the current window to allow the service worker take the control.
|
|
14
|
+
*/
|
|
15
|
+
updateServiceWorker: () => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|