forked from acaldas/document-model-electron
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.renderer.config.mts
128 lines (119 loc) · 4.4 KB
/
vite.renderer.config.mts
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
import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label';
import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh';
import path from 'path';
import { HtmlTagDescriptor, PluginOption, defineConfig, loadEnv } from 'vite';
import { viteEnvs } from 'vite-envs';
import { createHtmlPlugin } from 'vite-plugin-html';
import svgr from 'vite-plugin-svgr';
import pkg from './package.json';
import clientConfig from './client.config';
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
const env = loadEnv(mode, process.cwd());
const requiresHardRefreshEnv: unknown =
process.env.PH_CONNECT_APP_REQUIRES_HARD_REFRESH ??
env.PH_CONNECT_APP_REQUIRES_HARD_REFRESH;
const REQUIRES_HARD_REFRESH =
typeof requiresHardRefreshEnv === 'boolean'
? requiresHardRefreshEnv
: requiresHardRefreshEnv !== undefined
? requiresHardRefreshEnv === 'true'
: isProd;
const APP_VERSION =
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
(process.env.APP_VERSION ?? env.APP_VERSION ?? pkg.version).toString();
const authToken = process.env.SENTRY_AUTH_TOKEN ?? env.SENTRY_AUTH_TOKEN;
const org = process.env.SENTRY_ORG ?? env.SENTRY_ORG;
const project = process.env.SENTRY_PROJECT ?? env.SENTRY_PROJECT;
const release =
(process.env.SENTRY_RELEASE ?? env.SENTRY_RELEASE) || APP_VERSION;
const uploadSentrySourcemaps = authToken && org && project;
const plugins: PluginOption[] = [
react({
include: 'src/**/*.tsx',
babel: {
parserOpts: {
plugins: ['decorators'],
},
plugins: isProd ? [] : [jotaiDebugLabel, jotaiReactRefresh],
},
}),
svgr(),
createHtmlPlugin({
minify: true,
inject: {
tags: [
...(clientConfig.meta.map(meta => ({
...meta,
injectTo: 'head',
})) as HtmlTagDescriptor[]),
],
},
}),
viteEnvs({
computedEnv() {
return {
APP_VERSION,
REQUIRES_HARD_REFRESH,
SENTRY_RELEASE: release,
};
},
}),
] as const;
if (uploadSentrySourcemaps) {
plugins.push(
sentryVitePlugin({
release: {
name: release,
inject: false, // prevent it from injecting the release id in the service worker code, this is done in 'src/app/sentry.ts' instead
},
authToken,
org,
project,
}) as PluginOption,
);
}
return {
plugins,
build: {
minify: isProd,
sourcemap: isProd,
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
// Adds the service worker as a separate file
'service-worker': path.resolve(
__dirname,
'src/service-worker.ts',
),
},
output: {
// Ensure the service worker file goes to the root of the dist folder
entryFileNames: chunk => {
return ['service-worker'].includes(chunk.name)
? `${chunk.name}.js`
: 'assets/[name].[hash].js';
},
},
},
},
resolve: {
alias: {
'@/assets': path.resolve(__dirname, './assets'),
src: path.resolve(__dirname, './src'),
'connect-config': path.resolve(
__dirname,
'./src/connect.config.ts',
),
path: 'rollup-plugin-node-polyfills/polyfills/path',
events: 'rollup-plugin-node-polyfills/polyfills/events',
},
},
define: {
__APP_VERSION__: JSON.stringify(APP_VERSION),
__REQUIRES_HARD_REFRESH__: JSON.stringify(REQUIRES_HARD_REFRESH),
},
};
});