You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/pwa.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,23 @@ The `pwa` option can be a boolean or a string to control when the service worker
31
31
32
32
Since precaching every asset is heavy, `pwa` is **off by default** and should be enabled deliberately — most useful together with [`slidev build`](/guide/hosting) for a self-hosted deck you want to work offline.
33
33
34
+
## Installing the PWA Plugin
35
+
36
+
PWA support is powered by [`vite-plugin-pwa`](https://vite-pwa-org.netlify.app/), which ships as an **optional peer dependency**. It is not installed by default, so decks that don't opt into `pwa` never download it.
37
+
38
+
The first time you enable `pwa`, the Slidev CLI detects that the package is missing and prompts you to install it:
39
+
40
+
```
41
+
? The "pwa" option requires the "vite-plugin-pwa" package, which is not installed
42
+
in your project. Install it now? › (Y/n)
43
+
```
44
+
45
+
Confirm the prompt and Slidev installs it for you with your project's package manager (or globally, when Slidev itself is installed globally). In a non-interactive environment (such as CI) the prompt can't be shown, so install it ahead of time instead:
46
+
47
+
```bash
48
+
npm i -D vite-plugin-pwa
49
+
```
50
+
34
51
## How It Works
35
52
36
53
When you serve the built deck, the service worker downloads and caches all deck assets in the background. A small indicator in the bottom-right corner shows `Caching for offline…` while precaching is in progress, then briefly shows `Ready offline` once it completes. After that, disconnecting the network and reloading serves the whole deck — HTML, images, and video — from the cache.
// Check if stdin is available for prompts (i.e., is a TTY)
217
+
if(!process.stdin.isTTY){
218
+
console.error(
219
+
`${purpose} requires the "${pkgName}" package, which is not installed, and cannot prompt for installation. `
220
+
+`Install it with \`npm i -D ${pkgName}\` (or your package manager's equivalent) and try again.`,
221
+
)
222
+
process.exit(1)
223
+
}
224
+
225
+
const{ confirm }=awaitprompts({
226
+
name: 'confirm',
227
+
initial: 'Y',
228
+
type: 'confirm',
229
+
message: `${purpose} requires the "${yellow(pkgName)}" package, which is not installed ${underline(isInstalledGlobally.value ? 'globally' : 'in your project')}. Install it now?`,
230
+
})
231
+
232
+
if(!confirm)
233
+
process.exit(1)
234
+
235
+
if(isInstalledGlobally.value)
236
+
awaitrun(parseNi,['-g',pkgName])
237
+
else
238
+
awaitrun(parseNi,[pkgName])
239
+
}
240
+
169
241
/**
170
242
* Find the root of the package. If Slidev is installed globally, it will also search globally.
0 commit comments