-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
70 lines (69 loc) · 2.59 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
/* eslint-disable @typescript-eslint/no-unsafe-call */
import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import presets from './presets/presets'
export default defineConfig((env) => {
// env 环境变量
const viteEnv = loadEnv(env.mode, process.cwd())
return {
// envDir: resolve(__dirname),
base: viteEnv.VITE_BASE || './',
plugins: [presets(env)],
esbuild: {
drop: ['console', 'debugger'],
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'), // 把 @ 指向到 src 目录去
},
},
server: {
host: true, // host设置为true才可以使用network的形式,以ip访问项目
port: 3000,
open: true,
cors: true,
strictPort: true,
// 接口代理
proxy: {
'/api': {
target: 'http://master:8080/webroot/decision',
changeOrigin: true, // 允许跨域
// rewrite: (path) => path.replace('/api/', '/'),
},
// '/superset': {
// target: 'http://master:5000',
// changeOrigin: true,
// },
},
},
build: {
// outDir: resolve(__dirname, `dist`), // 指定输出路径
sourcemap: false, // 这个生产环境一定要关闭,不然打包的产物会很大
assetsInlineLimit: 4096, // 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求
emptyOutDir: true, // Vite 会在构建时清空该目录
reportCompressedSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 2000,
minify: 'esbuild',
assetsDir: 'static/assets',
// 静态资源打包到dist下的不同目录
rollupOptions: {
output: {
compact: true, // 压缩代码,删除换行符等
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
},
},
css: {
preprocessorOptions: {
// 全局引入了 scss 的文件
scss: {
additionalData: `@import "@/assets/styles/variables.scss";`,
javascriptEnabled: true,
},
},
},
}
})