-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.js
89 lines (85 loc) · 3.06 KB
/
vite.config.js
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
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import {compression} from 'vite-plugin-compression2'
import {createHtmlPlugin} from 'vite-plugin-html';
import zlib from 'zlib';
import fs from 'fs';
import {minify_sync} from 'terser';
import {WISH_ROOT, TEMPLATE_ROOT, WISH_VER} from './src/api_config';
const API_ENV = process.env['VITE_APP_MOCK_API_ENV'] || null;
const API_URL = API_ENV ? process.env['MOCK_API_URL_'+API_ENV] : 'https://geekgame.pku.edu.cn';
const API_COOKIE = API_ENV ? (process.env['MOCK_API_COOKIE_'+API_ENV] || null) : null;
const preload_script_src = minify_sync(
fs.readFileSync('src/index-preloaded.js', 'utf-8')
.replace(/\{__WISH_ROOT__}/g, WISH_ROOT)
.replace(/\{__WISH_VER__}/g, WISH_VER)
.replace(/\{__TEMPLATE_ROOT__}/g, TEMPLATE_ROOT)
).code;
export default defineConfig(() => {
return {
build: {
target: ['es2020', 'firefox78', 'chrome79', 'safari13'],
outDir: 'build',
assetsInlineLimit: 8192,
sourcemap: process.env.GENERATE_SOURCEMAP!=='false',
chunkSizeWarningLimit: 1500,
reportCompressedSize: false,
rollupOptions: {
output: {
compact: true,
generatedCode: 'es2015',
manualChunks: {
vendor: ['antd', '@ant-design/icons', 'react', 'react-dom', 'react-router-dom', 'react-transition-group', 'react-lazyload', 'react-timeago'],
Table: ['antd/es/table', 'antd/es/tree', 'antd/es/tree-select', 'rc-tree', './src/widget/Table'],
},
},
},
minify: 'terser',
terserOptions: {
ecma: 2020,
module: true,
compress: {
passes: 2,
},
},
},
esbuild: {
legalComments: 'none',
},
plugins: [
react(),
createHtmlPlugin({
minify: true,
inject: {
data: {
PRELOAD_SCRIPT: preload_script_src,
},
},
}),
compression({
include: /\.*$/,
exclude: /\.(png|jpg|jpeg|webp|mp3|ogg|webm)$/i,
algorithm: 'brotliCompress',
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
},
},
}),
],
server: {
open: true,
host: '0.0.0.0',
port: 3000,
proxy: {
'/service': {
target: API_URL,
changeOrigin: true,
ws: true,
headers: API_COOKIE ? {'Cookie': API_COOKIE} : {},
},
},
},
};
});