-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
100 lines (99 loc) · 3.37 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
import { defineConfig, UserConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig((config: UserConfig) => {
/* eslint-disable @typescript-eslint/no-unused-vars */
const isDev = config.mode === 'development'
const isDevBuild = config.mode === 'devbuild'
const isTest = config.mode === 'test'
const isProd = config.mode === 'production'
const isLib = config.mode === 'lib'
/* eslint-enable */
return {
base: isDev ? './' : './', // 打包路径
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, 'src'), // 设置 `@` 指向 `src` 目录
},
},
build: {
outDir: isLib ? 'dist' : 'docs',
lib: isLib ? {
entry: resolve(__dirname, 'src/condition-parser.ts'),
name: 'ConditionParser',
fileName: format => `condition-parser.${format}.js`,
} : false,
rollupOptions: {
// input: {
// index: resolve(__dirname, 'example.html'),
// },
// 确保外部化处理那些你不想打包进库的依赖
// external: ['vue'],
output: {
// name:'index',
// dir:'docs',
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
// globals: {
// vue: 'Vue'
// }
}
},
target: 'ES2015', //'esnext', //默认'modules',modules模式Opera、UC、百度浏览器不支持,由于对于移动端,不建议设置modules模式
assetsInlineLimit: 4096, //默认4096,小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求
cssCodeSplit: true, //默认true, CSS代码拆分
sourcemap: !isProd,
minify: 'terser', // 'terser' 相对较慢,但大多数情况下构建后的文件体积更小。'esbuild' 最小化混淆更快但构建后的文件相对更大。
terserOptions: {
compress: {
drop_console: isProd, // 生产环境去除console
drop_debugger: isProd, // 生产环境去除debugger
},
},
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
jsxInject: "import { h } from 'vue';",
},
server: {
port: 4005, // 启动端口
open: false, // 启动后是否打开浏览器。建议关闭,首次打开的页面会热更新,否则每次都会打开新的tab页。
cors: true, // 允许跨域
// 本地代理接口
proxy: {
// dev环境
'/api': {
target: '',
changeOrigin: true,
// rewrite: path => path.replace(/^\/collect/, 'collect'),
},
// test环境
// '/': {
// target: '',
// changeOrigin: true,
// // rewrite: path => path.replace(/^\/collect/, 'collect'),
// },
},
},
css: {
postcss: {
plugins: [
{
//解决构建包含@charset问题 https://github.com/vitejs/vite/issues/5833
//或者安装postcss-normalize-charset,应该也可以实现去除charset规则
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if (atRule.name === 'charset') {
atRule.remove()
}
},
},
},
],
},
},
}
})