-
Notifications
You must be signed in to change notification settings - Fork 58
/
vite.config.js
160 lines (149 loc) · 3.52 KB
/
vite.config.js
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { defineConfig } from 'vite';
const path = require('path');
import vue from '@vitejs/plugin-vue';
import legacy from '@vitejs/plugin-legacy';
import { viteMockServe } from 'vite-plugin-mock';
import { setting } from './src/config/setting';
import { svgBuilder } from './src/plugin/svgBuilder';
import OptimizationPersist from 'vite-plugin-optimize-persist';
import PkgConfig from 'vite-plugin-package-config';
import vueI18n from '@intlify/vite-plugin-vue-i18n';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
const {
base,
publicDir,
outDir,
assetsDir,
sourcemap,
cssCodeSplit,
host,
port,
strictPort,
open,
cors,
brotliSize,
logLevel,
clearScreen,
drop_console,
drop_debugger,
chunkSizeWarningLimit,
} = setting;
const isDev = process.env.NODE_ENV === 'development';
const loadI18n = isDev ? vueI18n({ include: path.resolve(__dirname, './src/locales/**') }) : '';
// https://vitejs.dev/config/
export default defineConfig({
root: process.cwd(),
base,
publicDir,
logLevel,
clearScreen,
plugins: [
vue(),
PkgConfig(),
OptimizationPersist(),
loadI18n,
legacy({
polyfills: ['es.promise.finally', 'es/map', 'es/set'],
modernPolyfills: ['es.promise.finally'],
}),
AutoImport({
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
imports: ['vue'],
resolvers: [
ElementPlusResolver(),
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
}),
Components({
resolvers: [
ElementPlusResolver({
importStyle: 'sass',
// directives: true,
// version: "2.1.5",
}),
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep'],
}),
],
}),
Icons({
autoInstall: true,
}),
viteMockServe({
mockPath: 'mock',
supportTs: false,
localEnabled: isDev,
prodEnabled: !isDev,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
}),
svgBuilder('./src/icons/svg/'),
],
server: {
host,
port,
cors,
strictPort,
open,
fs: {
strict: false,
},
},
resolve: {
// 设置别名
alias: {
views: path.resolve(__dirname, 'src/views'),
styles: path.resolve(__dirname, 'src/styles'),
'@': path.resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
// 引入公用的样式
scss: {
additionalData: `@use "@/styles/index.scss" as *; @use "@/styles/element/index.scss" as *;`,
charset: false,
},
},
},
corePlugins: {
preflight: false,
},
build: {
target: 'es2015',
outDir,
assetsDir,
sourcemap,
cssCodeSplit,
brotliSize,
// rollupOptions: {
// output: {
// // chunkFileNames: 'static/js/[name]-[hash].js',
// // entryFileNames: 'static/js/[name]-[hash].js',
// // assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// },
// },
terserOptions: {
compress: {
keep_infinity: true,
drop_console,
drop_debugger,
},
},
chunkSizeWarningLimit,
},
optimizeDeps: {
// 检测需要预构建的依赖项
include: [],
},
});