Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register service worker in dev #321

Merged
merged 8 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
build/
dist/
dev-dist/
node_modules/
*.svelte
*.d.ts
!.vitepress/dist/
3 changes: 2 additions & 1 deletion docs/.vitepress/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/vue-next/pull/3399
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

declare module '@vue/runtime-core' {
Expand All @@ -20,6 +20,7 @@ declare module '@vue/runtime-core' {
RouterView: typeof import('vue-router')['RouterView']
RunExamples: typeof import('./theme/components/RunExamples.md')['default']
SsrSsg: typeof import('./theme/components/SsrSsg.md')['default']
TypeScriptError2307: typeof import('./theme/components/TypeScriptError2307.md')['default']
}
}

Expand Down
16 changes: 16 additions & 0 deletions docs/.vitepress/theme/components/TypeScriptError2307.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
If your **TypeScript** build step or **IDE** complain about not being able to find modules or type definitions on imports, add the following to the `compilerOptions.types` array of your `tsconfig.json`:

```json
{
"compilerOptions": {
"types": [
"vite-plugin-pwa/client"
]
}
}
```

Or you can add the following reference in any of your `d.ts` files (for example, in `vite-env.d.ts` or `global.d.ts`):
```ts
/// <reference types="vite-plugin-pwa/client" />
```
1 change: 1 addition & 0 deletions docs/deployment/apache.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Apache Http Server 2.4+ | Deployment
next: Getting Started | Workbox
---

# Apache Http Server 2.4+
Expand Down
1 change: 1 addition & 0 deletions docs/deployment/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Getting Started | Deploy
prev: Astro | Examples
---

# Getting Started
Expand Down
1 change: 1 addition & 0 deletions docs/examples/astro.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Astro | Examples
next: Getting Started | Deploy
---

# Astro
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Getting Started | Examples
prev: Astro | Frameworks
---

# Getting Started
Expand Down Expand Up @@ -75,7 +76,7 @@ A common pitfall is to select `Offline` option, then restart the example project
If you click the browser `Refresh` button, you can inspect `Application > Network` tab on `dev tools` to check that the `Service Worker` is serving all assets instead request them to the server.

::: danger
Don't do a `hard refresh` since this will force the browser to go to the server, and then you will get `No internet connection` page on the browser.
Don't do a `hard refresh` since it will force the browser to go to the server, and then you will get `No internet connection` page.
:::

## Available Examples Projects
Expand Down
1 change: 1 addition & 0 deletions docs/frameworks/astro.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Astro | Frameworks
next: Getting Started | Examples
---

# Astro
Expand Down
5 changes: 5 additions & 0 deletions docs/frameworks/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Getting Started | Frameworks
prev: FAQ | Guide
---

# Getting Started
Expand All @@ -19,6 +20,10 @@ This plugin is Framework-agnostic and so you can use it with Vanilla JavaScript,

## Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register' {
export interface RegisterSWOptions {
Expand Down
4 changes: 4 additions & 0 deletions docs/frameworks/preact.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ You will need to add `workbox-window` as a `dev` dependency to your `Vite` proje

## Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register/preact' {
// @ts-expect-error ignore when preact/hooks is not installed
Expand Down
4 changes: 4 additions & 0 deletions docs/frameworks/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ You will need to add `workbox-window` as a `dev` dependency to your `Vite` proje

## Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register/react' {
// @ts-expect-error ignore when react is not installed
Expand Down
4 changes: 4 additions & 0 deletions docs/frameworks/solidjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ You will need to add `workbox-window` as a `dev` dependency to your `Vite` proje

## Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register/solid' {
// @ts-expect-error ignore when solid-js is not installed
Expand Down
4 changes: 4 additions & 0 deletions docs/frameworks/svelte.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ You will need to add `workbox-window` as a `dev` dependency to your `Vite` proje

## Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register/svelte' {
// @ts-expect-error ignore when svelte is not installed
Expand Down
4 changes: 4 additions & 0 deletions docs/frameworks/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ You can use the built-in `Vite` virtual module `virtual:pwa-register/vue` for `V

### Type declarations

::: tip
<TypeScriptError2307 />
:::

```ts
declare module 'virtual:pwa-register/vue' {
// @ts-expect-error ignore when vue is not installed
Expand Down
13 changes: 2 additions & 11 deletions docs/guide/faq.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
---
title: FAQ | Guide
next: Getting Started | Frameworks
---

# FAQ

## IDE errors 'Cannot find module' (ts2307)

If your TypeScript build step or IDE complain about not being able to find modules or type definitions on imports, add the following to the `compilerOptions.types` array of your `tsconfig.json`:

```json
{
"compilerOptions": {
"types": [
"vite-plugin-pwa/client"
]
}
}
```
<TypeScriptError2307 />

## Web app manifest and 401 status code (Unauthorized)

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/register-service-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ When configuring `injectRegister: 'script'` in the plugin configuration, the plu

::: details **/registerSW.js**
```js
if('serviceWorker' in navigator) {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js', { scope: '/' })
})
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/service-worker-precache.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineConfig({
VitePWA({
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*{js,css,html,ico,png,svg}']
globPatterns: ['**/*{js,css,html,ico,png,svg}']
}
})
]
Expand Down
18 changes: 9 additions & 9 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"serve": "npm run build && serve .vitepress/dist"
},
"dependencies": {
"@vueuse/core": "^8.5.0",
"@vueuse/shared": "^8.5.0",
"@vueuse/core": "^8.7.5",
"@vueuse/shared": "^8.7.5",
"vue": "^3.2.37"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@vitejs/plugin-vue": "^2.3.3",
"@vueuse/core": "^8.5.0",
"esbuild-register": "^3.3.2",
"eslint": "^8.16.0",
"@vueuse/core": "^8.7.5",
"esbuild-register": "^3.3.3",
"eslint": "^8.19.0",
"fast-glob": "^3.2.11",
"fs-extra": "^10.1.0",
"https-localhost": "^4.7.1",
"typescript": "^4.6.4",
"unocss": "^0.38.1",
"unplugin-vue-components": "^0.19.5",
"vite": "^2.9.9",
"typescript": "^4.7.4",
"unocss": "^0.38.2",
"unplugin-vue-components": "^0.19.9",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*",
"vitepress": "^1.0.0-alpha.4",
"workbox-window": "^6.5.3"
Expand Down
3 changes: 3 additions & 0 deletions docs/workbox/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
title: Getting Started | Workbox
prev:
text: Apache Http Server 2.4+ | Deployment
link: /deployment/apache
---

# Getting Started
Expand Down
8 changes: 4 additions & 4 deletions examples/preact-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
"serve": "serve dist"
},
"dependencies": {
"preact": "^10.7.2",
"preact": "^10.8.2",
"preact-router": "^4.0.1"
},
"devDependencies": {
"@preact/preset-vite": "^2.2.0",
"@preact/preset-vite": "^2.3.0",
"@rollup/plugin-replace": "^4.0.0",
"cross-env": "^7.0.3",
"https-localhost": "^4.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.4",
"vite": "^2.9.9",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*",
"workbox-core": "^6.5.3",
"workbox-precaching": "^6.5.3",
Expand Down
12 changes: 6 additions & 6 deletions examples/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
"serve": "serve dist"
},
"dependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.3.0",
"react-router-config": "^5.1.1",
"react-router-dom": "^6.3.0"
},
"devDependencies": {
"@rollup/plugin-replace": "^4.0.0",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.4",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/react-router-config": "^5.0.6",
"@types/react-router-dom": "^5.3.3",
"@vitejs/plugin-react-refresh": "^1.3.6",
"cross-env": "^7.0.3",
"https-localhost": "^4.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.4",
"vite": "^2.9.9",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*",
"workbox-core": "^6.5.3",
"workbox-precaching": "^6.5.3",
Expand Down
6 changes: 3 additions & 3 deletions examples/solid-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
},
"dependencies": {
"solid-app-router": "^0.3.3",
"solid-js": "^1.4.2"
"solid-js": "^1.4.5"
},
"devDependencies": {
"@rollup/plugin-replace": "^4.0.0",
"cross-env": "^7.0.3",
"https-localhost": "^4.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.4",
"vite": "^2.9.9",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*",
"vite-plugin-solid": "^2.2.6",
"workbox-core": "^6.5.3",
Expand Down
14 changes: 7 additions & 7 deletions examples/svelte-routify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
},
"devDependencies": {
"@rollup/plugin-replace": "^4.0.0",
"@roxi/routify": "^2.18.6",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.44",
"@roxi/routify": "^2.18.8",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.49",
"@tsconfig/svelte": "^3.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.16.0",
"eslint": "^8.19.0",
"eslint-plugin-svelte3": "^4.0.0",
"https-localhost": "^4.7.1",
"rimraf": "^3.0.2",
"svelte": "^3.48.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"typescript": "^4.6.4",
"vite": "^2.9.9",
"svelte-check": "^2.8.0",
"svelte-preprocess": "^4.10.7",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*",
"workbox-core": "^6.5.3",
"workbox-precaching": "^6.5.3",
Expand Down
12 changes: 6 additions & 6 deletions examples/sveltekit-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"@rollup/plugin-replace": "^4.0.0",
"@sveltejs/adapter-static": "next",
"@sveltejs/kit": "next",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@typescript-eslint/eslint-plugin": "^5.30.3",
"@typescript-eslint/parser": "^5.30.3",
"cross-env": "^7.0.3",
"eslint": "^8.16.0",
"eslint": "^8.19.0",
"eslint-plugin-svelte3": "^4.0.0",
"https-localhost": "^4.7.1",
"minimist": "^1.2.6",
"rimraf": "^3.0.2",
"svelte": "^3.48.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"svelte-check": "^2.8.0",
"svelte-preprocess": "^4.10.7",
"tslib": "^2.4.0",
"typescript": "^4.6.4",
"typescript": "^4.7.4",
"vite-plugin-pwa": "workspace:*",
"workbox-core": "^6.5.3",
"workbox-precaching": "^6.5.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/sveltekit-pwa/pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const buildPwa = async() => {
console.log('Generating PWA...')
await pwaPlugin.generateSW()
webmanifestDestinations.forEach(d => {
copyFileSync('./.svelte-kit/output/client/_app/manifest.webmanifest', `${d}/manifest.webmanifest`)
copyFileSync('./.svelte-kit/output/client/_app/immutable/manifest.webmanifest', `${d}/manifest.webmanifest`)
})
// don't copy workbox, svelte kit will copy it
if (pwaConfiguration.strategies === 'injectManifest') {
Expand Down
6 changes: 3 additions & 3 deletions examples/vue-basic-cdn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"devDependencies": {
"@rollup/plugin-replace": "^4.0.0",
"@vitejs/plugin-vue": "^2.3.3",
"@vueuse/core": "^8.5.0",
"@vueuse/core": "^8.7.5",
"cross-env": "^7.0.3",
"https-localhost": "^4.7.1",
"typescript": "^4.6.4",
"vite": "^2.9.9",
"typescript": "^4.7.4",
"vite": "^2.9.13",
"vite-plugin-pwa": "workspace:*"
}
}
Loading