Skip to content

Commit b75228c

Browse files
committed
feat: Add PWA support (#64)
1 parent 24bb01b commit b75228c

15 files changed

+1005
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
- 📑 [Layout system](./src/layouts)
3838

39+
- 📲 [PWA](https://github.com/antfu/vite-plugin-pwa)
40+
3941
- 🎨 [UnoCSS](https://github.com/antfu/unocss) - the instant on-demand atomic CSS engine
4042

4143
- 🔥 Use the [new `<script setup>` syntax](https://github.com/vuejs/rfcs/pull/227)
@@ -92,6 +94,7 @@
9294
- [vite-plugin-vue-devtools](https://github.com/vuejs/devtools-next) - Designed to enhance the Vue developer experience
9395
- [vueuse](https://github.com/antfu/vueuse) - collection of useful composition APIs
9496
- [@unhead/vue](https://github.com/unjs/unhead) - manipulate document head reactively
97+
- [vite-plugin-pwa](https://github.com/antfu/vite-plugin-pwa) - PWA
9598

9699
### Coding Style
97100

README.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
- 📑 [布局系统](./src/layouts)
3838

39+
- 📲 [PWA](https://github.com/antfu/vite-plugin-pwa)
40+
3941
- 🎨 [UnoCSS](https://github.com/antfu/unocss) - 高性能且极具灵活性的即时原子化 CSS 引擎
4042

4143
- 🔥 使用 [新的 `<script setup>` 语法](https://github.com/vuejs/rfcs/pull/227)
@@ -92,6 +94,7 @@
9294
- [vite-plugin-vue-devtools](https://github.com/vuejs/devtools-next) - 旨在增强Vue开发者体验的Vite插件
9395
- [vueuse](https://github.com/antfu/vueuse) - 实用的 Composition API 工具合集
9496
- [@unhead/vue](https://github.com/unjs/unhead) - 响应式地操作文档头信息
97+
- [vite-plugin-pwa](https://github.com/antfu/vite-plugin-pwa) - PWA
9598

9699
### 编码风格
97100

build/vite/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import VueDevTools from 'vite-plugin-vue-devtools'
1212
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
1313
import Layouts from 'vite-plugin-vue-layouts'
1414
import UnoCSS from 'unocss/vite'
15+
import { VitePWA } from 'vite-plugin-pwa'
1516
import { createViteVConsole } from './vconsole'
1617

1718
export function createVitePlugins() {
@@ -72,6 +73,35 @@ export function createVitePlugins() {
7273
// https://github.com/webfansplz/vite-plugin-vue-devtools
7374
VueDevTools(),
7475

76+
// https://github.com/antfu/vite-plugin-pwa
77+
VitePWA({
78+
registerType: 'autoUpdate',
79+
includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
80+
manifest: {
81+
name: 'vue3-vant-mobile',
82+
short_name: 'vue3-vant-mobile',
83+
theme_color: '#ffffff',
84+
icons: [
85+
{
86+
src: '/pwa-192x192.png',
87+
sizes: '192x192',
88+
type: 'image/png',
89+
},
90+
{
91+
src: '/pwa-512x512.png',
92+
sizes: '512x512',
93+
type: 'image/png',
94+
},
95+
{
96+
src: '/pwa-512x512.png',
97+
sizes: '512x512',
98+
type: 'image/png',
99+
purpose: 'any maskable',
100+
},
101+
],
102+
},
103+
}),
104+
75105
vueJsx(),
76106
visualizer(),
77107

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover, user-scalable=no"/>
6-
<link rel="icon" href="/favicon.ico" />
6+
<link rel="apple-touch-icon" href="/pwa-192x192.png" />
7+
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#f6d2d2">
8+
<meta name="msapplication-TileColor" content="#f6d2d2">
79
<script>
810
;(function () {
911
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "cross-env MOCK_SERVER_PORT=8086 vite",
1010
"build": "vue-tsc --noEmit && vite build",
1111
"build:dev": "vue-tsc --noEmit && vite build --mode=development",
12-
"preview": "npm run build && vite preview",
12+
"preview": "vite preview",
1313
"lint": "eslint .",
1414
"lint:fix": "eslint . --fix",
1515
"test": "vitest",
@@ -67,6 +67,7 @@
6767
"unplugin-vue-router": "^0.7.0",
6868
"vite": "^5.0.12",
6969
"vite-plugin-mock-dev-server": "^1.4.7",
70+
"vite-plugin-pwa": "^0.19.2",
7071
"vite-plugin-vconsole": "^2.1.1",
7172
"vite-plugin-vue-devtools": "^7.0.14",
7273
"vite-plugin-vue-layouts": "^0.11.0",

0 commit comments

Comments
 (0)