-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvite.config.ts
114 lines (107 loc) · 2.43 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
import { defineConfig } from 'vite'
import config from './vite.custom.config'
import pkg from './package.json'
import vitePlugins from './vite.plugin.config'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const { dependencies, devDependencies, name, version } = pkg
const {
server,
buildOptions,
alias,
copyright,
mixinCSS,
appPrimaryColor,
base,
} = config
const __APP_CFG__ = {
pkg: {
dependencies,
devDependencies,
name,
version,
},
layout: {
copyright,
},
appPrimaryColor,
}
return {
base: base || '/',
define: {
__APP_CFG__: JSON.stringify(__APP_CFG__),
__DEV__: mode === 'development',
},
resolve: {
alias: alias,
},
plugins: vitePlugins(mode),
optimizeDeps: {
include: [
'vue',
'vue-demi',
'vue-router',
'pinia',
'vue-i18n',
'naive-ui',
'@vueuse/core',
'dayjs',
'echarts',
'axios',
'print-js',
'clipboard',
'lodash-es',
'vue-hooks-plus',
'interactjs',
'pinia-plugin-persistedstate',
'currency.js',
'mockjs',
],
},
esbuild: {
pure: ['console.log'],
},
build: {
...buildOptions(mode),
rollupOptions: {
output: {
manualChunks: (id) => {
const isUtils = () => id.includes('src/utils/')
const isHooks = () => id.includes('src/hooks/')
const isNodeModules = () => id.includes('node_modules')
const index = id.includes('pnpm') ? 1 : 0 // 兼容 pnpm, yarn, npm 包管理器差异
if (isUtils()) {
return 'utils'
}
if (isHooks()) {
return 'hooks'
}
if (isNodeModules()) {
return id
.toString()
.split('node_modules/')[1]
.split('/')
[index].toString()
}
},
assetFileNames: '[ext]/[name]-[hash][extname]',
chunkFileNames: 'js/[name]-[hash].js',
entryFileNames: 'js/[name]-[hash].js',
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: mixinCSS,
},
},
modules: {
localsConvention: 'camelCaseOnly',
},
},
server: {
...server,
},
}
})