File size: 2,144 Bytes
d669ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import pkg from './package.json';
import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa';

const { name, version, dependencies, devDependencies } = pkg;
const __APP_INFO__ = {
  buildTimestamp: Date.now(),
  name,
  version,
  dependencies,
  devDependencies,
};

const initPwaOptions = (env: Record<string, string>) => {
  const pwaOptions: Partial<VitePWAOptions> = {
    srcDir: 'src',
    filename: 'sw.ts',
    includeAssets: ['img/logo.svg'],
    manifest: {
      name: 'BingAI',
      short_name: 'BingAI',
      theme_color: '#ffffff',
      icons: [
        {
          src: './img/pwa/logo-192.png',
          sizes: '192x192',
          type: 'image/png',
        },
        {
          src: './img/pwa/logo-512.png',
          sizes: '512x512',
          type: 'image/png',
        },
        {
          src: './img/pwa/logo-512.png',
          sizes: '512x512',
          type: 'image/png',
          purpose: 'any maskable',
        },
      ],
    },
    // devOptions: {
    //   enabled: true,
    //   type: 'module',
    // },
    strategies: 'injectManifest',
    // workbox: {
    //   cleanupOutdatedCaches: true,
    //   clientsClaim: true,
    //   skipWaiting: true,
    // },
    // 取消注册服务工作进程
    // selfDestroying: true,
    registerType: 'autoUpdate',
  };
  return pwaOptions;
};

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    base: '/web',
    server: {
      port: 4000,
      open: false,
      host: '0.0.0.0',
      proxy: {
        '^/(?!web)': {
          ws: true,
          target: env.VITE_BASE_API_URL,
          changeOrigin: false,
        },
      },
    },
    define: {
      __APP_INFO__: JSON.stringify(__APP_INFO__),
    },
    plugins: [vue(), VitePWA(initPwaOptions(env))],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    build: {
      outDir: '../web',
    },
  };
});