-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
82 lines (77 loc) · 1.9 KB
/
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
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
/// <reference types="vitest" />
import react from '@vitejs/plugin-react'
import fs from 'fs'
import path from 'path'
import {defineConfig} from 'vite'
import packageJson from './package.json'
import * as child from 'child_process'
import {execSync} from 'child_process'
import checker from 'vite-plugin-checker'
type Env = {
mode?: string
}
export default (env: Env) => {
const inDocker = fs.existsSync('/.dockerenv')
const isProd = env.mode === 'production'
console.log(`Running in ${isProd ? 'production' : 'development'} mode`)
const commitHash = child
.execSync('git rev-parse --short HEAD')
.toString()
.trim()
execSync(`echo ${commitHash} > public/version.txt`)
return defineConfig({
plugins: [
react(),
checker({
typescript: true,
eslint: {
lintCommand: 'eslint src',
useFlatConfig: true,
},
overlay: {
initialIsOpen: true,
},
}),
],
publicDir: './public',
define: {
__BUILD_INFO__: JSON.stringify({
appName: packageJson.name,
appBuildTime: new Date().toISOString(),
appVersion: `${new Date()
.toISOString()
.split('T')[0]
?.replace(/-/g, '')}-${commitHash}`,
commitHash,
}),
},
build: {
outDir: path.resolve(__dirname, 'build'),
sourcemap: 'hidden',
},
server: {
host: inDocker ? '0.0.0.0' : '127.0.0.1',
port: 3000,
},
preview: {
host: inDocker ? '0.0.0.0' : '127.0.0.1',
port: 3000,
},
test: {
coverage: {
provider: 'istanbul',
},
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{vite,vitest,build}.config.*',
'tests/components/*',
'tests/e2e/*',
],
},
resolve: {
alias: [{find: '~', replacement: '/src'}],
},
})
}