-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
125 lines (122 loc) · 3.68 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import type { UserConfig, ConfigEnv } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import { createProxy } from './build/vite/proxy';
import { wrapperEnv } from './build/utils';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import topLevelAwait from 'vite-plugin-top-level-await';
import MonacoEditorNlsPlugin from 'vite-plugin-monaco-editor';
import progress from 'vite-plugin-progress';
import colors from 'picocolors';
//https://github.com/element-plus/unplugin-element-plus/blob/HEAD/README.zh-CN.md
// vite.config.ts
import UnoCSS from 'unocss/vite';
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
console.log(command, mode);
const env = loadEnv(mode, root);
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const viteEnv = wrapperEnv(env);
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
return {
base: VITE_PUBLIC_PATH,
plugins: [
progress({
format: `${colors.green(colors.bold('Bouilding'))} ${colors.cyan('[:bar]')} :percent`,
}),
MonacoEditorNlsPlugin({
languageWorkers: ['json'],
}),
topLevelAwait({
// The export name of top-level await promise for each chunk module
promiseExportName: '__tla',
// The function to generate import names of top-level await promise in each chunk module
promiseImportName: (i) => `__tla_${i}`,
}),
vue(),
AutoImport({
dts: true, // or a custom path
// global imports to register
imports: [
// presets
'vue',
'vue-router',
'pinia',
// custom
{
'@vueuse/core': [
// named imports
'useMouse', // import { useMouse } from '@vueuse/core',
'useDark', // import { useDark } from '@vueuse/core',
'useToggle',
'onClickOutside',
],
axios: [
// default imports
['default', 'axios'], // import { default as axios } from 'axios',
],
},
// example type import
{
from: 'vue-router',
imports: ['RouteLocationRaw'],
type: true,
},
],
}),
Components({
extensions: ['vue', 'md'],
dts: 'src/components.d.ts',
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
resolvers: [
AntDesignVueResolver({
importStyle: false,
}),
],
}),
UnoCSS({
// configFile: "../my-uno.config.ts",
}),
],
publicDir: 'public',
server: {
host: '0.0.0.0',
port: VITE_PORT,
open: false,
strictPort: false,
proxy: createProxy(VITE_PROXY),
},
esbuild: {
drop: VITE_DROP_CONSOLE ? ['console', 'debugger'] : [],
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
components: resolve(__dirname, './src/components'),
api: resolve(__dirname, './src/api'),
},
},
css: {
// css预处理器
preprocessorOptions: {
scss: {
// charset: false,
additionalData: `@use "./src/assets/css/variable.scss" as *;`,
},
},
},
build: {
outDir: 'dist',
sourcemap: true,
target: 'modules',
// rollupOptions: {
// output: {
// manualChunks: {},
// },
// },
},
};
});