-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (85 loc) · 3.1 KB
/
vite.config.ts
File metadata and controls
92 lines (85 loc) · 3.1 KB
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
import { fileURLToPath, URL } from 'node:url';
import type { UserConfig, ConfigEnv } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Uni from '@uni-helper/plugin-uni'
import UniHelperComponents from '@uni-helper/vite-plugin-uni-components'
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
import UniHelperLayouts from '@uni-helper/vite-plugin-uni-layouts'
import UniHelperManifest from '@uni-helper/vite-plugin-uni-manifest'
import UniHelperPages from '@uni-helper/vite-plugin-uni-pages'
// 需要与 @uni-helper/vite-plugin-uni-pages 插件一起使用
import UniHelperPlatform from '@uni-helper/vite-plugin-uni-platform'
import UniHelperPolyfill from 'vite-plugin-uni-polyfill'
import UnoCSS from 'unocss/vite'
import UniKuRoot from '@uni-ku/root'
import { vitePluginConfig } from './build';
import { transformEnvConfType } from './build/utils';
import { createProxy } from './build/proxy';
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
const viteEnv = transformEnvConfType(loadEnv(mode, root));
const { VITE_DROP_CONSOLE, VITE_PORT, VITE_PROXY } = viteEnv;
return {
plugins: [
vueJsx(),
/** uni-app plugin */
UniHelperLayouts(),
UniHelperPlatform(),
UniHelperManifest(),
UniHelperPages({
exclude: ['**/components/**/**.*'],
// pages 目录为 src/pages,分包目录不能配置在pages目录下!!
// 是个数组,可以配置多个,但是不能为pages里面的目录!!
subPackages: ['src/subPages'],
dts: 'types/uni-pages.d.ts',
}),
// Components 需要在 Uni 之前引入
UniHelperComponents({
extensions: ['vue', 'jsx', 'tsx'],
deep: true, // 是否递归扫描子目录,
directoryAsNamespace: false, // 是否把目录名作为命名空间前缀,true 时组件名为 目录名+组件名,
dts: 'types/components.d.ts', // 自动生成的组件类型声明文件路径(用于 TypeScript 支持)
dirs: ['src/components'],
resolvers: [WotResolver()],
}),
UniKuRoot(),
Uni(),
UniHelperPolyfill(),
UnoCSS(),
/** ext vite plugin */
vitePluginConfig(viteEnv),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'#': fileURLToPath(new URL('./types', import.meta.url)),
},
},
server: {
// https: false,
// Listening on all local IPs
host: true,
port: VITE_PORT,
// Load proxy configuration from .env
proxy: createProxy(VITE_PROXY),
},
esbuild: {
// 移除日志打印及debugger
drop: VITE_DROP_CONSOLE ? ['console', 'debugger'] : [],
},
css: {
preprocessorOptions: {
// less: {
// javascriptEnabled: true,
// },
},
},
// 依赖优化 - 预构建
optimizeDeps: {
exclude: mode === 'development' ? ['vue', 'pinia', 'vue-router'] : [],
include: ['@vueuse/core'],
},
};
});