forked from dromara/yft-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
156 lines (153 loc) · 4.04 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
/*
* @Author: June
* @Description:
* @Date: 2023-05-25 18:41:35
* @LastEditors: June
* @LastEditTime: 2023-05-26 08:43:28
*/
import { VitePWA } from "vite-plugin-pwa";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { createHtmlPlugin } from "vite-plugin-html";
import type { ConfigEnv, UserConfigExport } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";
import autoprefixer from 'autoprefixer';
import viteCompression from 'vite-plugin-compression';
export default ({ command }: ConfigEnv): UserConfigExport => {
return {
base: "./", // publicPath
plugins: [
vue(),
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
}),
VitePWA({
registerType: "autoUpdate",
workbox: {
cacheId: "vue-fabric-draw-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: "vue-fabric-draw",
short_name: "vue-fabric-draw",
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: 'vue-fabric-draw'
}
}
})
],
css: {
postcss: {
plugins: [
autoprefixer()
]
},
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,
},
},
rollupOptions: {
output: {
manualChunks: {
vue: ['vue'],
fabric: ['fabric'],
'element-plus': ['element-plus']
}
}
}
},
};
};