-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
103 lines (101 loc) · 3.4 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
// Vite中文网:https://vitejs.cn/config/
import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { resolve } from 'path';
import uni from '@dcloudio/vite-plugin-uni';
import Unocss from 'unocss/vite';
import TransformPages from 'uni-read-pages-vite'; // vite.config.ts
import AutoImport from 'unplugin-auto-import/vite';
import Components from '@uni-helper/vite-plugin-uni-components';
import { NutResolver } from 'nutui-uniapp';
// https://vitejs.dev/config/
export default ({ mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
const env = loadEnv(mode, root);
return {
base: './',
// 设置路径别名
resolve: {
alias: {
'@': resolve('./src'),
},
extensions: ['.js', '.json', '.ts', '.vue'], // 使用路径别名时想要省略的后缀名,可以自己 增减
},
// 自定义全局变量
define: {
'process.env': {},
ROUTES: new TransformPages().routes,
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "nutui-uniapp/styles/variables.scss";',
},
},
},
// 开发服务器配置
server: {
host: true,
// open: true,
port: env.VITE_PORT as any,
proxy: {
[String(env.VITE_APP_BASE_API)]: {
target: env.VITE_APP_API_URL,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), ''),
},
'/upload': {
target: env.VITE_APP_API_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/upload/, ''),
},
},
},
// 构建配置
build: {
outDir: 'dist',
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
entryFileNames: `assets/[name].${new Date().getTime()}.js`,
chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
compact: true,
// manualChunks: {
// vue: ['vue', 'vue-router', 'vuex'],
// echarts: ['echarts'],
// },
},
},
},
// 插件
plugins: [
Components({
resolvers: [NutResolver()],
dirs: ['src/components', 'src/**/components'],
dts: 'typings/components.d.ts',
}),
// 自动导入
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
],
imports: [
'vue',
'uni-app',
'pinia',
{
'uni-mini-router': ['useRouter', 'useRoute'],
},
],
dts: 'typings/auto-imports.d.ts',
eslintrc: {
enabled: true,
},
}),
uni(),
Unocss(),
],
};
};