import { VitePWA } from 'vite-plugin-pwa'

export const pwaPlugin = (usePwa: boolean, title: string) => {
  if (usePwa) {
    const plugin = VitePWA({
      manifest: {
        name: title,
        short_name: title,
        theme_color: '#2C64F2',
        background_color: '#f7f9fa',
        lang: 'zh-CN'
      },
      registerType: 'autoUpdate',
      workbox: {
        globPatterns: ['**/*.{js,css,html,png,jpg,jpeg,svg}'],
        cleanupOutdatedCaches: false,
        sourcemap: false
      }
    })
    return plugin
  }
  return []
}
