forked from dromara/yft-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
222 lines (219 loc) · 6.58 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import { VitePWA } from "vite-plugin-pwa";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { createHtmlPlugin } from "vite-plugin-html";
import { visualizer } from "rollup-plugin-visualizer";
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import type { ConfigEnv, UserConfigExport } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";
import autoprefixer from 'autoprefixer';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import viteCompression from 'vite-plugin-compression';
import tailwindcss from 'tailwindcss'
export default ({ command }: ConfigEnv): UserConfigExport => {
return {
base: "./", // publicPath
server: {
host: 'localhost',
port: 5173,
proxy: {
'/api': {
// target: 'https://yft.design',
target: 'http://120.77.139.244:8789',
// target: 'http://127.0.0.1:8789',
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp('^'), ''),
},
'/static': {
// target: 'https://yft.design',
target: 'http://120.77.139.244:8789',
// target: 'http://127.0.0.1:8789',
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp('^'), ''),
},
'/yft-static': {
target: 'https://yft.design',
// target: 'http://120.77.139.244:8789',
// target: 'http://127.0.0.1:8789',
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp('^'), ''),
},
},
},
plugins: [
vue(),
visualizer({ open: true }),
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
}),
AutoImport({
imports: ['vue'],
dts: './src/types/auto-imports.d.ts',
eslintrc: {
enabled: true
},
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
VitePWA({
registerType: "autoUpdate",
workbox: {
cacheId: "yft-design-cache",
runtimeCaching: [
{
urlPattern: /.*/i,
handler: "NetworkFirst", // 接口网络优先
options: {
cacheName: "interface-cache",
},
},
{
urlPattern: /(.*?)\.(js|css|ts)/, // js /css /ts静态资源缓存
handler: "CacheFirst",
options: {
cacheName: "js-css-cache",
},
},
{
urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, // 图片缓存
handler: "CacheFirst",
options: {
cacheName: "image-cache",
},
},
],
},
manifest: {
name: "yft-design",
short_name: "yft-design",
theme_color: "#d14424",
icons: [
{
src: "./favicon.ico",
sizes: "192x192",
type: "image/png",
},
{
src: "./favicon.ico",
sizes: "512x512",
type: "image/png",
},
{
src: "./favicon.ico",
sizes: "192x192",
type: "image/png",
purpose: "maskable",
},
{
src: "./favicon.ico",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
start_url: "./index.html",
display: "standalone",
background_color: "#000000",
},
}),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), "src/icons/svg")], // icon存放的目录
symbolId: "icon-[name]", // symbol的id
inject: "body-last", // 插入的位置
customDomId: "__svg__icons__dom__", // svg的id
}),
createHtmlPlugin({
minify: true,
inject: {
data: {
title: 'yft-design'
}
}
})
],
css: {
postcss: {
plugins: [
tailwindcss,
autoprefixer({
// 自动添加前缀
overrideBrowserslist: [
'Android 4.1',
'iOS 7.1',
'Chrome > 31',
'ff > 31',
'ie >= 8',
'> 1%',
'last 2 versions',
'not dead',
'not ie 11',
//'last 2 versions', // 所有主流浏览器最近2个版本
],
grid: true,
}),
]
},
preprocessorOptions: {
scss: {
additionalData: `@import "src/assets/style/variable.scss";@import "src/assets/style/mixin.scss";`,
},
less: {
modifyVars: {
"primary-color": "#d14424",
"text-color": "#41464b",
"font-size-base": "13px",
"border-radius-base": "2px",
},
javascriptEnabled: true,
},
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
extensions: [".js", ".ts", ".jsx", ".tsx", ".vue", ".json"],
},
build: {
target: "es2015",
outDir: path.resolve(__dirname, "dist"),
minify: "terser",
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
// 关闭文件计算
reportCompressedSize: false,
// 关闭生成map文件
sourcemap: false,
rollupOptions: {
output: {
// chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
// entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
// assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等
manualChunks: {
vue: ['vue'],
fabric: ['fabric'],
'lodash-es': ['lodash-es'],
'opentype.js': ['opentype.js'],
'clipper-lib': ['clipper-lib'],
'element-plus': ['element-plus'],
},
// manualChunks(id, any): string {
// return id
// }
}
}
},
};
};