-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
95 lines (94 loc) · 2.34 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import inject from '@rollup/plugin-inject'
import viteCompression from 'vite-plugin-compression'
import { VitePWA } from 'vite-plugin-pwa'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
VitePWA({
includeAssets: ['logo.svg'],
manifest: false,
registerType: 'autoUpdate',
workbox: {
runtimeCaching: [
{
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',
},
},
],
},
}),
//viteCompression()
],
assetsInclude: ['src/assets/*'],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@page': resolve(__dirname, 'src/page'),
'/img': resolve(__dirname, 'src/assets/img'),
stream: 'stream-browserify',
process: 'process/browser',
zlib: 'browserify-zlib',
util: 'util',
},
},
optimizeDeps: {
exclude: ['@fortawesome/fontawesome-free'],
},
base: './',
server: {
port: 3000,
},
define: {
'process.env.BASE_URL': '"/"',
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
exclude: ['node_modules/lodash-es/**'],
},
rollupOptions: {
// @ts-ignore
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
output: {
// manualChunks(id) {
// if (id.includes('node_modules')) {
// return id
// .toString()
// .split('node_modules/')[1]
// .split('/')[0]
// .toString()
// }
// },
manualChunks(id) {
if (id.includes('node_modules')) {
if (
id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.includes('naive-ui')
) {
return 'naive-ui'
} else {
return 'vendor'
}
}
},
},
},
},
})