-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
144 lines (143 loc) · 4.67 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//element plus 按需引入
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import visualizer from 'rollup-plugin-visualizer'
import postCssPxToRem from "postcss-pxtorem"
const { name }: Record<string, any> = require('./package.json')
const isProduction = process.env.NODE_ENV === 'production'
// const ONLINENAME = 'http://wgms.dev.fpi-inc.site'
const ONLINENAME = 'http://yhwszz.fpi-inc.site'
export default defineConfig({
plugins: [
vue(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/ // .md
],
resolvers: [
ElementPlusResolver(),
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
imports: ['vue', 'vue-router', 'pinia'],
eslintrc: {
enabled: false, // 默认false, true启用。生成一次就可以,避免每次工程启动都生成
filepath: './.eslintrc-auto-import.json', // 生成json文件
globalsPropValue: true
},
// 声明文件生成位置和文件名称
dts: './src/auto-import.d.ts'
}),
Components({
resolvers: [
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep'],
}),
ElementPlusResolver()
]
}),
Icons({
autoInstall: true,
}),
visualizer(),
],
base: isProduction ? `/${name}/` : '/',
build: {
// 生成静态资源的存放路径
assetsDir: 'static/img/',
// 构建后是否生成 source map 文件
sourcemap: !isProduction,
// chunk 大小警告的限制
chunkSizeWarningLimit: 1500,
// 生产环境移除 console debugger
minify: 'terser',
terserOptions: {
compress: {
// drop_console: isProduction,
drop_debugger: isProduction
}
},
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// 解决打包时Some chunks are larger警告
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
}
}
}
}
},
resolve: {
alias: {
'@': '/src/',
'@components': '/src/components/',
'@assets': '/src/assets/',
'@utils': '/src/utils/',
'@config': '/src/config/',
'@styles': '/src/styles/',
'@types': '/src/types/',
'@static': '/public/static'
}
},
server: {
port: 3077,
open: true,
proxy: {
'/api': {
target: ONLINENAME,
rewrite: path => path.replace(/^\/api/, ''),
changeOrigin: true
}
}
},
css: {
// 处理打包出现警告 "@charset" must be the first
postcss: {
plugins: [
postCssPxToRem({
rootValue: 192, // 1rem的大小
propList: ['*', '!border*'],
selectorBlackList: ['.nearby-search-control']
}),
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if (atRule.name === 'charset') {
atRule.remove()
}
}
}
},
]
},
preprocessorOptions: {
scss: {
additionalData: `
@use "./src/styles/mixins.scss" as *;
@use "./src/styles/el-reset.scss" as *;
`,
charset: false
},
}
}
})