feat: PWA 默认不开启

main
ChenZhaoYu 2 years ago
parent 92278932ef
commit d2a22a3ee5

@ -5,3 +5,6 @@ VITE_APP_API_BASE_URL=http://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

@ -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;
}

@ -1,19 +1,13 @@
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'
export default defineConfig((env) => {
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
function setupPlugins(env: ImportMetaEnv): PluginOption[] {
const plugins = [vue()]
return {
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
},
},
plugins: [
vue(),
if (env.VITE_GLOB_APP_PWA === 'true') {
VitePWA({
injectRegister: 'auto',
manifest: {
@ -24,8 +18,21 @@ export default defineConfig((env) => {
{ 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
return {
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
},
},
plugins: setupPlugins(viteEnv),
server: {
host: '0.0.0.0',
port: 1002,

Loading…
Cancel
Save