-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
146 lines (139 loc) · 3.75 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import * as process from 'node:process'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { visualizer } from 'rollup-plugin-visualizer'
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 viteStylelint from '@amatlash/vite-plugin-stylelint'
// import { chunkSplitPlugin } from 'vite-plugin-chunk-split'
const environment = process.env.NODE_ENV || 'development'
let server = {}
if (environment === 'development') {
server = {
cors: true,
host: '0.0.0.0',
port: 8000,
proxy: {
'/api': {
target: 'http://localhost:9000',
changeOrigin: true,
// secure: true
},
},
}
}
else {
server = {
cors: true,
host: '0.0.0.0',
proxy: {
'/api': {
target: 'https://weather-api.zyha.cn',
changeOrigin: true,
// secure: true
},
},
}
}
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
extensions: ['.mjs', '.js', '.cjs','.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: {
'@': '/src',
},
},
css: {
preprocessorOptions: {
css: {
devSourceMap: true,
},
scss: {
charset: false,
additionalData: `
@import '@/assets/scss/mixin.scss';
@import '@/assets/scss/comm.scss';
@import '@/assets/scss/variable.scss';`,
},
// https://github.com/vitejs/vite/issues/5833
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule: any) => {
if (atRule.name === 'charset')
atRule.remove()
},
},
},
],
},
},
},
server,
optimizeDeps: {
include: [
'echarts',
'vuex',
// "pinia",
// "vue-i18n",
// "lodash-es",
'@vueuse/core',
// "@iconify/vue",
// "element-plus/lib/locale/lang/en",
'element-plus/es/locale/lang/zh-cn',
// "vxe-table/lib/locale/lang/zh-CN",
// "vxe-table/lib/locale/lang/en-US"
],
// exclude: ["@zougt/vite-plugin-theme-preprocessor/dist/browser-utils"]
},
build: {
sourcemap: false,
reportCompressedSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 2000,
minify: false,
rollupOptions: {
output: {
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// chunkFileNames: (chunkInfo) => {
// const facadeModuleId = chunkInfo.facadeModuleId ? chunkInfo.facadeModuleId.split('/') : []
// const fileName = facadeModuleId[facadeModuleId.length - 2] || '[name]'
// return `js/${fileName}/[name].[hash].js`
manualChunks(id) {
if (id.includes('node_modules') && id.includes('element'))
return 'element'
else if (id.includes('node_modules') && (id.includes('echarts')))
return 'echarts'
else if (id.includes('node_modules') && id.includes('vue'))
return 'vue'
else if (id.includes('node_modules'))
return 'vendor'
},
},
},
},
plugins: [
vue(),
// chunkSplitPlugin({
// strategy: 'unbundle',
// }),
Icons({ autoInstall: true, compiler: 'vue3' }),
visualizer(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
// viteStylelint({
// // 对某些文件排除检查
// exclude: /windicss|node_modules/,
// }),
],
// base:'/weather-fe/'
// base: './'
})