forked from Orginone/oiocns-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
110 lines (106 loc) · 3.34 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import dayjs from 'dayjs';
import path from 'path';
import type { ConfigEnv, UserConfig } from 'vite';
import { PORT, VITE_BASE_PATH, VITE_DROP_CONSOLE } from './config/constant';
import { themeVariables } from './config/theme';
import { createVitePlugins } from './config/vite/plugins';
import { createProxy } from './config/vite/proxy';
import pkg from './package.json';
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
};
// 函数式配置
export default ({ command, mode }: ConfigEnv): UserConfig => {
const isBuild = command === 'build';
return {
base: VITE_BASE_PATH,
plugins: createVitePlugins(mode, isBuild),
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: themeVariables,
},
},
},
resolve: {
alias: [
{ find: /^~/, replacement: '' },
{ find: '@', replacement: path.resolve(__dirname, 'src') },
{ find: '@cfg', replacement: path.resolve(__dirname, 'config') },
],
},
server: {
// 是否主动唤醒浏览器
open: false,
// 占用端口 开发环境启动的端口
port: PORT,
// 是否使用https请求
// https: true,
// 扩展访问端口
host: true,
hmr: true,
watch: {
usePolling: true, // WSL必须,否则热更新无效
},
proxy: createProxy(),
},
build: {
target: 'es5',
outDir: 'dist', // 指定输出路径
minify: 'terser', // 混淆器,terser构建后文件体积更小
sourcemap: false, // 输出.map文件
chunkSizeWarningLimit: 2048,
terserOptions: {
compress: {
drop_console: VITE_DROP_CONSOLE, // 生产环境移除console
drop_debugger: true, // 生产环境移除debugger
pure_funcs: ['console.log'],
},
output: {
// 去掉注释内容
comments: true,
},
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
// external: ['react', 'antd'], // 注意看这里
treeshake: false,
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// manualChunks(id) {
// if (id.includes('components')) {
// // 把 components 文件里面的文件都打包到 components.js 中
// return 'components';
// }
// // 静态资源拆分
// if (id.includes('node_modules')) {
// return id.toString().split('node_modules/')[1].split('/')[0].toString();
// }
// },
},
plugins: [
{
name: 'no-treeshake',
transform(_, id) {
if (id.includes('integration/jquery')) {
return { moduleSideEffects: 'no-treeshake' };
}
if (id.includes('ui/data_grid')) {
return { moduleSideEffects: 'no-treeshake' };
}
},
},
],
},
},
define: {
// 设置应用信息
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
};
};