-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.js
115 lines (115 loc) · 2.7 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import path from 'path'
import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
import viteCompression from 'vite-plugin-compression'
import vitePluginImp from 'vite-plugin-imp'
import visualizer from 'rollup-plugin-visualizer'
import htmlMinifier from 'vite-plugin-html-minifier-terser'
import banner from './plugin/banner'
import copyPlugin from 'vite-plugin-files-copy'
// @ts-ignore
const env = process.argv[process.argv.length - 1]
const isProd = env === 'production'
// https://vitejs.dev/config/
export default defineConfig({
base: isProd ? '/vite-react-hooks-bigdata/' : '/',
/**
* 与“根”相关的目录,构建输出将放在其中。如果目录存在,它将在构建之前被删除。
* @default 'dist'
*/
publicDir: 'dist',
mode: 'development',
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
// 配置代理
server: {
host: '0.0.0.0',
port: 8080,
open: true,
// proxy: {
// '/api': {
// target: 'localhost:4000',
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '')
// }
// }
},
css: {
preprocessorOptions: {
scss: {
charset: false,
},
less: {
javascriptEnabled: true,
},
},
},
plugins: [
reactRefresh(),
// 复制文件
// @ts-ignore
copyPlugin({
patterns: [
{
from: './public',
to: './dist',
},
],
}),
// 压缩编译后的html
// @ts-ignore
htmlMinifier(),
// 给打包的代码加上信息
// @ts-ignore
banner(`
author: tcly861204
email: tcly861204@hotmail.com
date: ${new Date().toLocaleString()}
github: https://github.com/tcly861204/vite-react-hooks-bigdata
`),
vitePluginImp({
libList: [
{
libName: 'antd',
style: (name) => `antd/es/${name}/style`,
},
],
}),
isProd &&
viteCompression({
// 压缩
ext: '.br',
verbose: false,
threshold: 10 * 1024,
filter: /\.(js|mjs|json|css)$/i,
algorithm: 'brotliCompress',
}),
isProd &&
visualizer({
open: false,
gzipSize: true,
brotliSize: true,
filename: 'dist/report.html',
}),
],
build: {
outDir: 'dist',
assetsDir: 'assets',
emptyOutDir: true,
cssCodeSplit: true,
sourcemap: false,
manifest: true,
brotliSize: true, // 是否启用 brotli 压缩,IE 不支持
chunkSizeWarningLimit: 300, // chunk 超大警告显示
terserOptions: {
// 生产环境移除console
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
})