-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
52 lines (44 loc) · 958 Bytes
/
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
import * as path from 'path'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
// Add the paths required for the aliases
const paths = [
"assets",
"components",
"context",
"fonts",
"hooks",
"pages",
"routes",
"styles",
"utils",
]
/**
* Function to create the aliases
* @returns An array with the aliases
*/
const getAliases = () => paths.map(p => ({ find: `@${p}`, replacement: path.resolve(__dirname, `src/${p}`) }))
interface config {
resolve: object;
plugins: any[]
[key: string]: any;
}
/**
* Initial configuration for Vite
*/
export default defineConfig(({ command, mode }) => {
// console.log({ command, mode })
const config: config = {
plugins: [react()],
resolve: {
alias: getAliases(),
}
}
if (mode === 'development') {
const env = loadEnv(mode, process.cwd())
config.server = {
port: env.VITE_PORT || 3000,
}
}
return config
})