Skip to content

Commit

Permalink
feat: PWA 默认不开启
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanzhaoyu committed Mar 22, 2023
1 parent 9227893 commit d2a22a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ VITE_APP_API_BASE_URL=http:https://localhost:3002/

# Whether long replies are supported, which may result in higher API fees
VITE_GLOB_OPEN_LONG_REPLY=false

# When you want to use PWA
VITE_GLOB_APP_PWA=false
3 changes: 2 additions & 1 deletion src/typings/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

interface ImportMetaEnv {
readonly VITE_GLOB_API_URL: string;
readonly VITE_GLOB_API_TIMEOUT: string;
readonly VITE_APP_API_BASE_URL: string;
readonly VITE_GLOB_OPEN_LONG_REPLY: string;
readonly VITE_GLOB_APP_PWA: string;
}
35 changes: 21 additions & 14 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import path from 'path'
import type { PluginOption } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'

function setupPlugins(env: ImportMetaEnv): PluginOption[] {
const plugins = [vue()]

if (env.VITE_GLOB_APP_PWA === 'true') {
VitePWA({
injectRegister: 'auto',
manifest: {
name: 'chatGPT',
short_name: 'chatGPT',
icons: [
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
],
},
})
}
return plugins
}

export default defineConfig((env) => {
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv

Expand All @@ -12,20 +32,7 @@ export default defineConfig((env) => {
'@': path.resolve(process.cwd(), 'src'),
},
},
plugins: [
vue(),
VitePWA({
injectRegister: 'auto',
manifest: {
name: 'chatGPT',
short_name: 'chatGPT',
icons: [
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
],
},
}),
],
plugins: setupPlugins(viteEnv),
server: {
host: '0.0.0.0',
port: 1002,
Expand Down

0 comments on commit d2a22a3

Please sign in to comment.