forked from yihong0618/running_page
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
115 lines (112 loc) · 3.6 KB
/
vite.config.ts
File metadata and controls
115 lines (112 loc) · 3.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
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
import process from 'node:process';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgr from 'vite-plugin-svgr';
import tailwindcss from '@tailwindcss/vite';
// The following are known larger packages or packages that can be loaded asynchronously.
const individuallyPackages = [
'activities',
'github.svg',
'grid.svg',
'mol.svg',
];
const colorClassMapping: { [key: string]: string } = {
// Background
'#1a1a1a': 'svg-color-bg',
'#222': 'svg-color-bg',
'#444': 'svg-color-inactive-cell',
'#4dd2ff': 'svg-color-active-cell',
// Primary Text
'#fff': 'svg-color-text',
'#e1ed5e': 'svg-color-text',
};
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
viteTsconfigPaths(),
svgr({
include: ['**/*.svg'],
svgrOptions: {
exportType: 'named',
namedExport: 'ReactComponent',
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
svgoConfig: {
floatPrecision: 2,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
removeViewBox: false,
},
},
},
{
name: 'addClassesByFillColor',
fn: () => {
return {
element: {
enter: (node) => {
const fillColor = node.attributes.fill;
if (fillColor) {
const lowerCaseFill = fillColor.toLowerCase();
if (colorClassMapping[lowerCaseFill]) {
node.attributes.class =
colorClassMapping[lowerCaseFill];
}
}
const strokeColor = node.attributes.stroke;
if (strokeColor) {
const lowerCaseStroke = strokeColor.toLowerCase();
if (colorClassMapping[lowerCaseStroke]) {
// If class already exists, append, otherwise set.
const existingClass = node.attributes.class || '';
const newClass = colorClassMapping[lowerCaseStroke];
if (!existingClass.includes(newClass)) {
node.attributes.class =
`${existingClass} ${newClass}`.trim();
}
}
}
},
},
};
},
},
],
},
},
}),
],
base: process.env.PATH_PREFIX || '/',
define: {
'import.meta.env.VERCEL': JSON.stringify(process.env.VERCEL),
},
build: {
manifest: true,
outDir: './dist', // for user easy to use, vercel use default dir -> dist
rollupOptions: {
output: {
manualChunks: (id: string) => {
if (id.includes('node_modules')) {
return 'vendors';
// If there will be more and more external packages referenced in the future,
// the following approach can be considered.
// const name = id.split('node_modules/')[1].split('/');
// return name[0] == '.pnpm' ? name[1] : name[0];
} else {
for (const item of individuallyPackages) {
if (id.includes(item)) {
return item;
}
}
}
},
},
},
},
});