-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.mts
92 lines (85 loc) · 2.52 KB
/
vite.config.mts
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
/// <reference types="vitest" />
// Plugins
import Components from 'unplugin-vue-components/vite';
import Vue from '@vitejs/plugin-vue';
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
import ViteFonts from 'unplugin-fonts/vite';
import bodyParser from 'body-parser';
// Utilities
import { defineConfig } from 'vite';
import { fileURLToPath, URL } from 'node:url';
let initialPageRequestMark: number;
const InitialPageRequestMarker = () => ({
name: 'initial-page-request-marker',
configureServer(server) {
server.middlewares.use((request, _response, next) => {
if (request.url === '/') {
initialPageRequestMark = Date.now();
}
next();
});
},
});
const InitialGridConstructionLatencyMeasurer = () => ({
name: 'initial-grid-construction-latency-measurer',
configureServer(server) {
server.middlewares.use(bodyParser.json());
server.middlewares.use((request, response, next) => {
if (request.url === '/measure-initial-grid-construction-latency') {
if (initialPageRequestMark !== undefined) {
const completedInitialImageDataGridConstructionMark =
+request.body.completedInitialImageDataGridConstructionMark;
console.log(
'Initial grid construction latency measure:',
completedInitialImageDataGridConstructionMark -
initialPageRequestMark
);
initialPageRequestMark = undefined;
}
response.statusCode = 200;
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify({ message: 'Request received' }));
} else {
next();
}
});
},
});
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
Vue({
template: { transformAssetUrls },
}),
// https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin#readme
Vuetify(),
Components(),
ViteFonts({
google: {
families: [
{
name: 'Roboto',
styles: 'wght@100;300;400;500;700;900',
},
],
},
}),
InitialPageRequestMarker(),
InitialGridConstructionLatencyMeasurer(),
],
define: { 'process.env': {} },
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@test': fileURLToPath(new URL('./test', import.meta.url)),
},
extensions: ['.js', '.json', '.jsx', '.mjs', '.ts', '.tsx', '.vue'],
},
server: {
port: 3000,
},
test: {
globals: true,
environment: 'jsdom',
},
});