forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
137 lines (131 loc) · 5.43 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as path from 'path';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import macrosPlugin from 'vite-plugin-babel-macros';
import { viteStaticCopy } from 'vite-plugin-static-copy';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Via https://stackoverflow.com/a/66389044.
const env = loadEnv(mode, process.cwd(), '');
process.env = { ...process.env, ...env };
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
const themeConfig = require(`./src/conf/theme/${process.env.REACT_APP_THEME_CONFIG}`);
// Setup proxy to the datahub-frontend service.
const frontendProxy = {
target: process.env.REACT_APP_PROXY_TARGET || 'http://localhost:9002',
changeOrigin: true,
};
const proxyOptions = {
'/logIn': frontendProxy,
'/authenticate': frontendProxy,
'/api/v2/graphql': frontendProxy,
'/track': frontendProxy,
};
return {
appType: 'spa',
plugins: [
react(),
svgr(),
macrosPlugin(),
viteStaticCopy({
targets: [
// Self-host images by copying them to the build directory
{ src: path.resolve(__dirname, 'src/images/*'), dest: 'assets/platforms' },
// Also keep the theme json files in the build directory
{ src: path.resolve(__dirname, 'src/conf/theme/*.json'), dest: 'assets/conf/theme' },
],
}),
viteStaticCopy({
targets: [
// Copy monaco-editor files to the build directory
// Because of the structured option, specifying dest .
// means that it will mirror the node_modules/... structure
// in the build directory.
{
src: 'node_modules/monaco-editor/min/vs/',
dest: '.',
},
{
src: 'node_modules/monaco-editor/min-maps/vs/',
dest: '.',
rename: (name, ext, fullPath) => {
console.log(name, ext, fullPath);
return name;
},
},
],
structured: true,
}),
],
// optimizeDeps: {
// include: ['@ant-design/colors', '@ant-design/icons', 'lodash-es', '@ant-design/icons/es/icons'],
// },
envPrefix: 'REACT_APP_',
build: {
outDir: 'dist',
target: 'esnext',
minify: 'esbuild',
reportCompressedSize: false,
// Limit number of worker threads to reduce CPU pressure
workers: 3, // default is number of CPU cores
},
server: {
open: false,
host: false,
port: 3000,
proxy: proxyOptions,
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
// Override antd theme variables.
// https://4x.ant.design/docs/react/customize-theme#Ant-Design-Less-variables
modifyVars: themeConfig.styles,
},
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
css: true,
// reporters: ['verbose'],
coverage: {
enabled: true,
provider: 'v8',
reporter: ['text', 'json', 'html'],
include: ['src/**/*'],
reportsDirectory: '../build/coverage-reports/datahub-web-react/',
exclude: [],
},
},
resolve: {
alias: {
// Root Directories
'@src': path.resolve(__dirname, '/src'),
'@app': path.resolve(__dirname, '/src/app'),
'@conf': path.resolve(__dirname, '/src/conf'),
'@components': path.resolve(__dirname, 'src/alchemy-components'),
'@graphql': path.resolve(__dirname, 'src/graphql'),
'@graphql-mock': path.resolve(__dirname, 'src/graphql-mock'),
'@images': path.resolve(__dirname, 'src/images'),
'@providers': path.resolve(__dirname, 'src/providers'),
'@utils': path.resolve(__dirname, 'src/utils'),
// App Specific Directories
'@app/entityV1': path.resolve(__dirname, 'src/app/entity'),
'@app/entityV2': path.resolve(__dirname, 'src/app/entityV2'),
'@app/searchV2': path.resolve(__dirname, 'src/app/searchV2'),
'@app/domainV2': path.resolve(__dirname, 'src/app/domainV2'),
'@app/glossaryV2': path.resolve(__dirname, 'src/app/glossaryV2'),
'@app/homeV2': path.resolve(__dirname, 'src/app/homeV2'),
'@app/lineageV2': path.resolve(__dirname, 'src/app/lineageV2'),
'@app/previewV2': path.resolve(__dirname, 'src/app/previewV2'),
'@app/sharedV2': path.resolve(__dirname, 'src/app/sharedV2'),
// Specific Files
'@types': path.resolve(__dirname, 'src/types.generated.ts'),
},
},
};
});