-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
66 lines (57 loc) 路 1.9 KB
/
Copy pathvite.config.ts
File metadata and controls
66 lines (57 loc) 路 1.9 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
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
import { createClientConfig } from './config/vite-client';
import {
defaultDevServerPort,
getViteCacheDir as getViteCacheDirForRoot,
resolveDevServerPort,
serverRuntimeBuildMode,
} from './config/vite-dev-server';
import {
copyServerPromptAssets,
createServerRuntimeConfig,
isServerRuntimeBuild,
} from './config/vite-server-runtime';
const __dirname = dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf8')) as {
dependencies?: Record<string, string>;
version?: string;
};
export { copyServerPromptAssets, defaultDevServerPort, resolveDevServerPort, serverRuntimeBuildMode };
export const getViteCacheDir = (command: 'build' | 'serve', argv: string[], mode?: string) =>
getViteCacheDirForRoot(__dirname, command, argv, mode);
export default defineConfig(({ command, mode }) => {
const enableCodeInspector = command === 'serve' && !process.env.VITEST;
const enableReactScan = command === 'serve' && !process.env.VITEST;
const sharedConfig = {
cacheDir: getViteCacheDir(command, process.argv, mode),
define: {
__APP_VERSION__: JSON.stringify(packageJson.version ?? '0.0.0'),
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
dedupe: ['react', 'react-dom'],
},
test: {
include: ['src/**/*.test.{js,ts,jsx,tsx}', 'scripts/**/*.test.{js,ts,jsx,tsx}'],
},
};
if (isServerRuntimeBuild(command, mode)) {
return createServerRuntimeConfig({
packageMetadata: packageJson,
rootDir: __dirname,
sharedConfig,
});
}
return createClientConfig({
enableCodeInspector,
enableReactScan,
env: process.env,
rootDir: __dirname,
sharedConfig,
});
});