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

feat: support PWA #6

Merged
merged 9 commits into from
Mar 1, 2025
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
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover"
/>
<meta name="description" content="A crafted mobile template" />
<meta name="theme-color" content="#ffffff" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="icon" href="/favicon.png" type="image/png" />
<link rel="stylesheet" href="/app-loading.css" />
<title>%VITE_APP_TITLE%</title>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"unplugin-auto-import": "19.1.1",
"unplugin-vue-components": "28.4.1",
"vite": "6.2.0",
"vite-plugin-pwa": "0.21.1",
"vite-svg-loader": "5.1.0",
"vitest": "3.0.7",
"vue-tsc": "2.2.6"
Expand Down
Binary file added public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pwa-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/robota.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Allow: /
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@@/*": ["src/common/*"]
},
"resolveJsonModule": true,
"types": ["vite/client"],
"types": ["vite/client", "vite-plugin-pwa/client"],
// 允许导入 .ts .mts .tsx 拓展名的文件
"allowImportingTsExtensions": true,
// 允许 JS
Expand Down
29 changes: 29 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import UnoCSS from "unocss/vite"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { defineConfig, loadEnv } from "vite"
import { VitePWA } from "vite-plugin-pwa"
import svgLoader from "vite-svg-loader"

// Configuring Vite: https://cn.vite.dev/config
Expand Down Expand Up @@ -121,6 +122,34 @@ export default defineConfig(({ mode }) => {
Components({
dts: "types/auto/components.d.ts",
resolvers: [VantResolver()]
}),
// PWA
VitePWA({
includeAssets: ["favicon.png", "apple-touch-icon.png"],
manifest: {
name: "MobVue",
short_name: "MobVue",
description: "A crafted mobile template",
theme_color: "#ffffff",
icons: [
{
src: "pwa-192x192.png",
sizes: "192x192",
type: "image/png"
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png"
},
{
src: "pwa-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: ["any", "maskable"]
}
]
}
})
],
// Configuring Vitest: https://cn.vitest.dev/config
Expand Down