This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
94 lines (93 loc) · 2.79 KB
/
vite.config.ts
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
93
94
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import viteCompression from 'vite-plugin-compression';
import htmlMinimize from '@sergeymakinen/vite-plugin-html-minimize'
import { minify_sync } from "terser";
import path from 'path'
import fs from 'fs'
// https://vitejs.dev/config/
export default defineConfig({
server: {
// 监听所有地址(包括局域网与公网),方便内网调试
host: '0.0.0.0',
cors: false,
proxy: {
'/api': {
target: 'http://localhost:24124',
changeOrigin: true,
rewriteWsOrigin: true,
},
},
},
base: './',
plugins: [
react(),
viteCompression({ algorithm: "brotliCompress", threshold: 256 }),
viteCompression({ algorithm: "gzip", threshold: 256 }),
{
name: "minify loading-failed.js",
apply: "build",
enforce: "post",
closeBundle() {
const name = "dist/loading-failed.js"
const src = fs.readFileSync(name).toString()
const output = minify_sync(src, {
compress: {
arrows: false,
typeofs: false,
}
})
if (output.code) fs.writeFileSync(name, output.code)
},
},
htmlMinimize({
minifierOptions: {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
html5: true,
keepClosingSlash: false,
minifyCSS: true,
minifyJS: false,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true,
includeAutoGeneratedTags: false,
}
}),
],
build: {
target: 'esnext',
minify: 'terser',
terserOptions: {
format: {
comments: false,
},
},
rollupOptions: {
input: {
index: path.resolve("index.html"),
login: path.resolve("login.html"),
},
},
reportCompressedSize: false, // 是否使用vite自带的方式打印压缩后的大小
modulePreload: {
polyfill: false,
},
chunkSizeWarningLimit: Infinity,
cssCodeSplit: true,
assetsInlineLimit: 0,
},
esbuild: {
legalComments: "none",
},
css: {
preprocessorOptions: {
scss: {
api: 'modern',
},
},
},
})