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/react/pwa.md
+52-12
Original file line number
Diff line number
Diff line change
@@ -7,29 +7,69 @@ sidebar_label: Progressive Web Apps
7
7
<title>Create Progressive Web Apps (PWA) in React - Ionic Framework</title>
8
8
<meta
9
9
name="description"
10
-
content="Create progressive web apps in React with Ionic. Read our React PWA documentation for information on how to make React PWAs using the Ionic CLI."
10
+
content="Create progressive web apps in React with Ionic. Read our React PWA documentation for information on how to make React PWAs."
11
11
/>
12
12
</head>
13
13
14
-
## Making your React app a PWA
14
+
## Making your React app a PWA with Vite
15
15
16
-
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Manifest</a>. While it's possible to add both of these to an app manually, a base project from Create React App (CRA) and the Ionic CLI provides this already.
16
+
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Application Manifest</a>. While it's possible to add both of these to an app manually, we recommend using the [Vite PWA Plugin](https://vite-pwa-org.netlify.app/) instead.
17
+
18
+
To get started, install the `vite-plugin-pwa` package:
19
+
20
+
```shell
21
+
npm install -D vite-plugin-pwa
22
+
```
23
+
24
+
Next, update your `vite.config.js` or `vite.config.ts` file and add `vite-plugin-pwa`:
25
+
26
+
```javascript
27
+
import { defineConfig } from'vite'
28
+
importreactfrom'@vitejs/plugin-react'
29
+
import { VitePWA } from'vite-plugin-pwa'
30
+
31
+
exportdefaultdefineConfig({
32
+
plugins: [
33
+
react(),
34
+
VitePWA({ registerType:'autoUpdate' })
35
+
],
36
+
})
37
+
```
38
+
39
+
This minimal configuration allows your application to generate the Web Application Manifest and Service Worker on build.
40
+
41
+
For more information on configuring the Vite PWA Plugin, see the [Vite PWA "Getting Started" Guide](https://vite-pwa-org.netlify.app/guide/).
42
+
43
+
See the [Vite PWA "Deploy" Guide](https://vite-pwa-org.netlify.app/deployment/) for information on how to deploy your PWA.
44
+
45
+
## Making your React app a PWA with Create React App
46
+
47
+
:::note
48
+
As of Ionic CLI v7, Ionic React starter apps ship with Vite instead of Create React App. See [Making your React app a PWA with Vite](#making-your-react-app-a-pwa-with-vite) for Vite instructions.
49
+
:::
50
+
51
+
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Application Manifest</a>. While it's possible to add both of these to an app manually, a base project from Create React App (CRA) and the Ionic CLI provides this already.
17
52
18
53
In the `index.ts` for your app, there is a call to a `serviceWorker.unregister()` function. The base that CRA provides has service workers as an opt-in feature, so it must be enabled. To enable, call `serviceWorker.register()`.
// If you want your app to work offline and load faster, you can change
29
70
// unregister() to register() below. Note this comes with some pitfalls.
30
-
// Learn more about service workers: https://bit.ly/CRA-PWA
31
-
// serviceWorker.unregister();
32
-
serviceWorker.register();
71
+
// Learn more about service workers: https://cra.link/PWA
72
+
serviceWorkerRegistration.register();
33
73
```
34
74
35
75
Once this package has been added, run `ionic build` and the `build` directory will be ready to deploy as a PWA.
@@ -42,15 +82,15 @@ By default, react apps package comes with the Ionic logo for the app icons. Be s
42
82
Features like Service Workers and many JavaScript APIs (such as geolocation) require the app to be hosted in a secure context. When deploying an app through a hosting service, be aware that HTTPS will be required to take full advantage of Service Workers.
43
83
:::
44
84
45
-
## Service Worker configuration
85
+
###Service Worker configuration
46
86
47
87
By default, CRA/React Scripts come with a preconfigured Service Worker setup based on [Workbox's Webpack plugin](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin). This utilises a cache-first strategy, meaning that your app will load from a cache, even if the network returns a newer version of the app.
48
88
49
89
Because of the nature of CRA/React Scripts, the configuration for this is internal to React Scripts, meaning that it cannot be customized without ejecting from React Scripts. Currently, the Ionic CLI does not support an ejected React App, so if this action is taken, you'll need to use npm/yarn scripts instead of the Ionic CLI.
50
90
51
-
## Deploying
91
+
###Deploying
52
92
53
-
### Firebase
93
+
####Firebase
54
94
55
95
Firebase hosting provides many benefits for Progressive Web Apps, including fast response times thanks to CDNs, HTTPS enabled by default, and support for [HTTP2 push](https://firebase.googleblog.com/2016/09/http2-comes-to-firebase-hosting.html).
Copy file name to clipboardExpand all lines: docs/vue/pwa.md
+39-5
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
---
2
+
title: Progressive Web Apps in Vue
2
3
sidebar_label: Progressive Web Apps
3
4
---
4
5
@@ -10,11 +11,44 @@ sidebar_label: Progressive Web Apps
10
11
/>
11
12
</head>
12
13
13
-
#Progressive Web Apps in Vue
14
+
## Making your Vue app a PWA with Vite
14
15
15
-
## Making your Vue app a PWA
16
+
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Application Manifest</a>. While it's possible to add both of these to an app manually, we recommend using the [Vite PWA Plugin](https://vite-pwa-org.netlify.app/) instead.
16
17
17
-
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Manifest</a>. While it's possible to add both of these to an app manually, the Vue CLI has some utilities for adding this for you.
18
+
To get started, install the `vite-plugin-pwa` package:
19
+
20
+
```shell
21
+
npm install -D vite-plugin-pwa
22
+
```
23
+
24
+
Next, update your `vite.config.js` or `vite.config.ts` file and add `vite-plugin-pwa`:
25
+
26
+
```javascript
27
+
import { defineConfig } from'vite'
28
+
importvuefrom'@vitejs/plugin-vue'
29
+
import { VitePWA } from'vite-plugin-pwa'
30
+
31
+
exportdefaultdefineConfig({
32
+
plugins: [
33
+
vue(),
34
+
VitePWA({ registerType:'autoUpdate' })
35
+
],
36
+
})
37
+
```
38
+
39
+
This minimal configuration allows your application to generate the Web Application Manifest and Service Worker on build.
40
+
41
+
For more information on configuring the Vite PWA Plugin, see the [Vite PWA "Getting Started" Guide](https://vite-pwa-org.netlify.app/guide/).
42
+
43
+
See the [Vite PWA "Deploy" Guide](https://vite-pwa-org.netlify.app/deployment/) for information on how to deploy your PWA.
44
+
45
+
## Making your Vue app a PWA with Vue CLI
46
+
47
+
:::note
48
+
As of Ionic CLI v7, Ionic Vue starter apps ship with Vite instead of Vue CLI. See [Making your Vue app a PWA with Vite](#making-your-vue-app-a-pwa-with-vite) for Vite instructions.
49
+
:::
50
+
51
+
The two main requirements of a PWA are a <ahref="https://developers.google.com/web/fundamentals/primers/service-workers/"target="_blank">Service Worker</a> and a <ahref="https://developers.google.com/web/fundamentals/web-app-manifest/"target="_blank">Web Application Manifest</a>. While it's possible to add both of these to an app manually, the Vue CLI has some utilities for adding this for you.
18
52
19
53
For existing projects, you can run the `vue add` command to install the PWA plugin for Vue.
20
54
@@ -117,11 +151,11 @@ In addition to the service worker, the Vue PWA plugin also is responsible for cr
117
151
118
152
Be sure to update the icons in `public/img/icons` to match your own brand. If you wanted to customize the theme color or name, be sure to read the [PWA plugin docs](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa#configuration) on GitHub.
119
153
120
-
## Deploying
154
+
###Deploying
121
155
122
156
You can use various hosts like Firebase, Vercel, Netlify, or even Azure Static Web Apps. All will have similar setup processes that need to be completed. For this guide, Firebase will be used as the hosting example. In addition to this guide, the [Vue CLI docs](https://cli.vuejs.org/guide/deployment.html) also have a guide on how to deploy to various providers.
123
157
124
-
### Firebase
158
+
####Firebase
125
159
126
160
Firebase hosting provides many benefits for Progressive Web Apps, including fast response times thanks to CDNs, HTTPS enabled by default, and support for [HTTP2 push](https://firebase.googleblog.com/2016/09/http2-comes-to-firebase-hosting.html).
0 commit comments