forked from jason5ng32/MyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
131 lines (120 loc) · 3.31 KB
/
Copy pathvite.config.js
File metadata and controls
131 lines (120 loc) · 3.31 KB
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
import dotenv, { parse } from 'dotenv';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from '@tailwindcss/vite'
import { serwist } from '@serwist/vite'
import { CodeInspectorPlugin } from 'code-inspector-plugin';
dotenv.config();
const backEndPort = parseInt(process.env.BACKEND_PORT || 11966, 10);
const frontEndPort = parseInt(process.env.FRONTEND_PORT || 18966, 10);
const nodeModuleChunkGroups = {
vendor: ['vue', 'vue-router', 'vue-i18n'],
chart: ['chart.js'],
speedtest: ['@cloudflare/speedtest'],
svgmap: ['svgmap'],
'browser-detect': ['@thumbmarkjs/thumbmarkjs', 'detect-gpu', 'ua-parser-js'],
};
const sourceChunkGroups = {
'utils-getips': [
'/frontend/utils/getips/index',
'/frontend/utils/valid-ip',
'/frontend/utils/transform-ip-data',
'/frontend/utils/masked-info'
],
'utils-data': [
'/frontend/utils/country-name',
'/frontend/utils/speedtest-colos'
],
'utils-auth': [
'/frontend/utils/authenticated-fetch'
],
'utils-analytics': [
'/frontend/utils/use-analytics'
]
};
function isNodePackage(normalizedId, packageName) {
const nodeModulesPath = '/node_modules/';
const nodeModulesIndex = normalizedId.lastIndexOf(nodeModulesPath);
if (nodeModulesIndex === -1) {
return false;
}
const packagePath = normalizedId.slice(nodeModulesIndex + nodeModulesPath.length);
return packagePath === packageName || packagePath.startsWith(`${packageName}/`);
}
function manualChunks(id) {
const normalizedId = id.replaceAll('\\', '/');
for (const [chunkName, packages] of Object.entries(nodeModuleChunkGroups)) {
if (packages.some((packageName) => isNodePackage(normalizedId, packageName))) {
return chunkName;
}
}
for (const [chunkName, modules] of Object.entries(sourceChunkGroups)) {
if (modules.some((moduleName) => normalizedId.includes(moduleName))) {
return chunkName;
}
}
return undefined;
}
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === 'pwa-install'
}
}
}),
tailwindcss(),
serwist({
swSrc: 'frontend/sw.js',
swDest: 'sw.js',
globDirectory: 'dist',
globPatterns: [
'**/*.{js,css,woff,woff2}',
'*.{js,css,png,svg,jpg,webp}',
],
}),
CodeInspectorPlugin({
bundler: 'vite',
hideDomPathAttr: true,
behavior: {
copy: '{file}',
},
}),
],
resolve: {
alias: {
'@': '/frontend',
},
},
build: {
rollupOptions: {
output: {
manualChunks,
assetFileNames: (assetInfo) => {
if (assetInfo.fileName && (assetInfo.fileName.endsWith('.woff') || assetInfo.fileName.endsWith('.woff2'))) {
return 'fonts/[name][extname]';
}
return 'assets/[name]-[hash][extname]';
},
chunkFileNames: (chunkInfo) => {
const prefix = chunkInfo.name.startsWith('utils-') ? 'utils/' : '';
return `assets/${prefix}[name].[hash].js`;
}
}
},
chunkSizeWarningLimit: 1000,
splitChunks: {
chunks: 'all',
minSize: 20000,
maxSize: 500000,
}
},
server: {
host: '0.0.0.0',
port: frontEndPort,
proxy: {
'/api': `http://localhost:${backEndPort}`
}
}
})