-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (85 loc) · 2.94 KB
/
Copy pathvite.config.ts
File metadata and controls
92 lines (85 loc) · 2.94 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
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import webfontDownload from 'vite-plugin-webfont-dl';
import reactSwc from '@vitejs/plugin-react-swc';
import { execSync } from 'child_process';
import { compression } from 'vite-plugin-compression2';
import checker from 'vite-plugin-checker';
import { ValidateEnv as validateEnv } from '@togglecorp/vite-plugin-validate-env';
import managerDashboardPackage from './package.json';
/* 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).'
);
}
}
const commitHash = getCommitHash();
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
return {
define: {
'import.meta.APP_COMMIT_HASH': JSON.stringify(commitHash),
'import.meta.env.APP_VERSION': JSON.stringify(managerDashboardPackage.version),
'import.meta.env.APP_ID': JSON.stringify('mapswipe-manager-dashboard'),
},
plugins: [
isProd ? checker({
// typescript: true,
eslint: {
lintCommand: 'eslint ./app',
},
stylelint: {
lintCommand: 'stylelint "./app/**/*.css"',
},
}) : undefined,
reactSwc(),
tsconfigPaths(),
webfontDownload(),
validateEnv(),
isProd ? compression() : undefined,
],
css: {
devSourcemap: isProd,
modules: {
scopeBehaviour: 'local',
localsConvention: 'camelCaseOnly',
},
},
envPrefix: 'APP_',
server: {
port: 3000,
strictPort: true,
host: '0.0.0.0',
},
build: {
outDir: 'build',
sourcemap: isProd,
rollupOptions: {
output: {
chunkFileNames: 'chunk-[name].[hash].js',
entryFileNames: 'entry-[name].[hash].js',
assetFileNames: 'asset-[name]-[hash].[ext]',
manualChunks: {
'mapillary-js': ['mapillary-js'],
'maplibre-gl': ['maplibre-gl'],
}
// experimentalMinChunkSize: 500_000,
},
},
},
test: {
// NOTE: happy-dom is configured nowhere in dependencies; use node
// until DOM-based tests are actually added
environment: 'node',
dir: 'app',
},
};
});