-
Notifications
You must be signed in to change notification settings - Fork 45
/
vite.config.ts
82 lines (72 loc) · 2.11 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
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import {defineConfig, loadEnv} from 'vite';
import {ViteDevServer} from 'vite';
import {visualizer} from 'rollup-plugin-visualizer';
const pluginWatchNodeModules = (modules: string[]) => {
const pattern = `/node_modules\\/(?!${modules.join('|')}).*/`;
return {
name: 'watch-node-modules',
configureServer: (server: ViteDevServer): void => {
server.watcher.options = {
...server.watcher.options,
ignored: [new RegExp(pattern), '**/.git/**'],
};
},
};
};
// Plugin so we can use default %env_variable%
const htmlEnvPlugin = (mode: string) => {
const env = loadEnv(mode, 'env');
// Default deploy-version to npm package version when the environment variable
// is not set (e.g. local build)
env['VITE_REACT_APP_DEPLOY_VERSION'] ??= process.env.npm_package_version!;
return {
name: 'html-transform',
transformIndexHtml: (html: string) =>
html.replace(/%(.*?)%/g, (_, p1) => env[p1]),
};
};
// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
const watchMode = process.env.WATCH === 'true';
const analyze = process.env.ANALYZE === 'true';
return {
base: '',
plugins: [
htmlEnvPlugin(mode),
react(),
tsconfigPaths(),
watchMode ? pluginWatchNodeModules(['@aragon/ods']) : undefined,
analyze ? visualizer({open: true}) : undefined,
],
optimizeDeps: {
exclude: watchMode ? ['@aragon/ods'] : undefined,
esbuildOptions: {
target: 'es2020',
},
},
resolve: {
preserveSymlinks: !watchMode,
alias: watchMode
? {'@aragon/ods': '@aragon/ods/dist/index.es'}
: undefined,
},
build: {
target: 'es2020',
rollupOptions: {
output: {
manualChunks: {
'osx-ethers': ['@aragon/osx-ethers'],
tiptap: [
'@tiptap/extension-link',
'@tiptap/extension-placeholder',
'@tiptap/react',
'@tiptap/starter-kit',
],
},
},
},
},
};
});