-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
72 lines (69 loc) · 2.16 KB
/
Copy pathvite.config.ts
File metadata and controls
72 lines (69 loc) · 2.16 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
import babel from '@rolldown/plugin-babel';
import react, { reactCompilerPreset } from '@vitejs/plugin-react';
import { execSync } from 'child_process';
import { defineConfig } from 'vite';
import checker from 'vite-plugin-checker';
import svgr from 'vite-plugin-svgr';
import { ValidateEnv as validateEnv } from '@togglecorp/vite-plugin-validate-env';
/* Get commit hash */
function getCommitHash(): string {
if (process.env.APP_COMMIT_HASH) {
return process.env.APP_COMMIT_HASH;
}
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch (error) {
throw new Error(
'Unable to determine commit hash. You must either provide a commit hash using the APP_COMMIT_HASH environment variable,'
+ " or provide a valid Git repository (submodule doesn't work with docker).", { cause: error },
);
}
}
const commitHash = getCommitHash();
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
return {
define: {
APP_COMMIT_HASH: JSON.stringify(commitHash),
},
plugins: [
isProd
? checker({
typescript: true,
eslint: {
lintCommand: 'eslint ./app',
},
stylelint: {
lintCommand: 'stylelint "./app/**/*.css"',
},
})
: undefined,
svgr(),
validateEnv({
configFile: 'env',
}),
react(),
babel({ presets: [reactCompilerPreset()] }),
],
resolve: {
tsconfigPaths: true
},
css: {
devSourcemap: isProd,
modules: {
scopeBehaviour: 'local',
localsConvention: 'camelCaseOnly',
},
},
sourcemap: isProd,
build: {
outDir: 'build',
sourcemap: isProd,
},
envPrefix: 'APP_',
server: {
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 3000,
strictPort: true,
},
};
});