forked from lewkamtao/lew-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
80 lines (79 loc) · 3.19 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
import { defineConfig, ConfigEnv } from 'vite';
import compressPlugin from 'vite-plugin-compression';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv) => {
return {
resolve: {
//设置别名
alias: {
'lew-ui': path.resolve(__dirname, 'packages'),
'@': path.resolve(__dirname, 'src'),
},
// 忽略后缀名的配置选项, 添加 .vue 选项时要记得原本默认忽略的选项也要手动写入
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
// compressPlugin开启gzip压缩
plugins: [
vue(),
compressPlugin({
ext: '.gz',
deleteOriginFile: false, // 是否删除原始文件
}),
],
build:
mode == 'package'
? {
lib: {
entry: path.resolve(__dirname, './packages/index.ts'),
name: 'lew-ui',
fileName: (format) => `lew.${format}.ts`,
},
minify: 'terser',
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: ['vue'],
output: {
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: 'Vue',
},
},
},
}
: {
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames:
'assets/static/[name]-[hash].[ext]',
manualChunks(id: any) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString();
}
},
},
},
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
};
});