-
Notifications
You must be signed in to change notification settings - Fork 17
/
vite.config.ts
69 lines (62 loc) · 1.62 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
import { join } from 'path';
import { readFileSync } from 'fs';
import { ResolvedConfig, UserConfigExport, defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { peerDependencies } from './package.json';
const DEV_SERVER_PORT = 8000;
// Commit information to identify the build
function getBuildId(): string {
try {
const versionPath = join(__dirname, '..', '..', 'VERSION');
const versionData = readFileSync(versionPath)
.toString()
.split(/[\r\n]+/);
const [, branch] = versionData
.find(line => line.includes('GIT_BRANCH'))!
.split('=');
const [, shortHash] = versionData
.find(line => line.includes('GIT_SHORT_HASH'))!
.split('=');
return `${shortHash}@${branch}`;
} catch (err) {
console.log(err);
return 'no-git';
}
}
// https://vitejs.dev/config/
export default ({
command,
}: Pick<ResolvedConfig, 'command' | 'mode'>): UserConfigExport => {
const baseConfig = defineConfig({
define: {
// eslint-disable-next-line @typescript-eslint/naming-convention
__REQUIRED_SERVER_VERSION__: `'${peerDependencies['@nest-react/server']}'`,
},
resolve: {
alias: {
'~': join(__dirname, 'src'),
},
},
plugins: [react()],
});
if (command === 'serve') {
return {
...baseConfig,
server: {
port: DEV_SERVER_PORT,
},
};
}
const assetsDir = 'assets';
return {
...baseConfig,
build: {
sourcemap: true,
rollupOptions: {
output: {
entryFileNames: join(assetsDir, `[name].${getBuildId()}.[hash].js`),
},
},
},
};
};