Skip to content

Commit d2a22a3

Browse files
committed
feat: PWA 默认不开启
1 parent 9227893 commit d2a22a3

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ VITE_APP_API_BASE_URL=http://localhost:3002/
55

66
# Whether long replies are supported, which may result in higher API fees
77
VITE_GLOB_OPEN_LONG_REPLY=false
8+
9+
# When you want to use PWA
10+
VITE_GLOB_APP_PWA=false

src/typings/env.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
interface ImportMetaEnv {
44
readonly VITE_GLOB_API_URL: string;
5-
readonly VITE_GLOB_API_TIMEOUT: string;
65
readonly VITE_APP_API_BASE_URL: string;
6+
readonly VITE_GLOB_OPEN_LONG_REPLY: string;
7+
readonly VITE_GLOB_APP_PWA: string;
78
}

vite.config.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
import path from 'path'
2+
import type { PluginOption } from 'vite'
23
import { defineConfig, loadEnv } from 'vite'
34
import vue from '@vitejs/plugin-vue'
45
import { VitePWA } from 'vite-plugin-pwa'
56

7+
function setupPlugins(env: ImportMetaEnv): PluginOption[] {
8+
const plugins = [vue()]
9+
10+
if (env.VITE_GLOB_APP_PWA === 'true') {
11+
VitePWA({
12+
injectRegister: 'auto',
13+
manifest: {
14+
name: 'chatGPT',
15+
short_name: 'chatGPT',
16+
icons: [
17+
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
18+
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
19+
],
20+
},
21+
})
22+
}
23+
return plugins
24+
}
25+
626
export default defineConfig((env) => {
727
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
828

@@ -12,20 +32,7 @@ export default defineConfig((env) => {
1232
'@': path.resolve(process.cwd(), 'src'),
1333
},
1434
},
15-
plugins: [
16-
vue(),
17-
VitePWA({
18-
injectRegister: 'auto',
19-
manifest: {
20-
name: 'chatGPT',
21-
short_name: 'chatGPT',
22-
icons: [
23-
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
24-
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
25-
],
26-
},
27-
}),
28-
],
35+
plugins: setupPlugins(viteEnv),
2936
server: {
3037
host: '0.0.0.0',
3138
port: 1002,

0 commit comments

Comments
 (0)