-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathvite.config.js
More file actions
79 lines (77 loc) · 2.6 KB
/
Copy pathvite.config.js
File metadata and controls
79 lines (77 loc) · 2.6 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
import { defineConfig } from 'vite';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
export default defineConfig({
root: 'src',
publicDir: '../public',
appType: 'mpa',
plugins: [
{
name: 'mpa-route-rewrites',
configureServer(server) {
server.middlewares.use((req, _res, next) => {
const url = req.url || '';
try {
const { pathname } = new URL(url, 'http://localhost');
if (pathname === '/dashboard' || pathname === '/dashboard/') {
req.url = '/dashboard/index.html';
} else if (pathname === '/login' || pathname === '/login/') {
req.url = '/login/index.html';
} else if (pathname === '/signup' || pathname === '/signup/') {
req.url = '/signup/index.html';
}
} catch {}
next();
});
},
configurePreviewServer(server) {
server.middlewares.use((req, _res, next) => {
const url = req.url || '';
try {
const { pathname } = new URL(url, 'http://localhost');
if (pathname === '/dashboard' || pathname === '/dashboard/') {
req.url = '/dashboard/index.html';
} else if (pathname === '/login' || pathname === '/login/') {
req.url = '/login/index.html';
} else if (pathname === '/signup' || pathname === '/signup/') {
req.url = '/signup/index.html';
}
} catch {}
next();
});
}
}
],
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: resolve(__dirname, 'src/index.html'),
dashboard: resolve(__dirname, 'src/dashboard/index.html'),
login: resolve(__dirname, 'src/login/index.html'),
signup: resolve(__dirname, 'src/signup/index.html'),
},
output: {
entryFileNames: (chunkInfo) => {
if (chunkInfo.name === 'main') {
return 'assets/[name]-[hash].js';
}
return '[name]/[name]-[hash].js';
},
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split('.');
const ext = info[info.length - 1];
if (/png|jpe?g|gif|svg|webp|ico/.test(ext)) {
return 'assets/[name]-[hash][extname]';
} else if (/css/.test(ext)) {
return 'assets/[name]-[hash][extname]';
}
return 'assets/[name]-[hash][extname]';
}
}
},
},
});