-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvite.config.renderer.ts
147 lines (134 loc) · 4.29 KB
/
vite.config.renderer.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
138
139
140
141
142
143
144
145
146
147
/// <reference types="vitest/config" />
import { cpus } from 'node:os';
import { resolve } from 'node:path';
import { type Plugin, type UserConfigFn } from 'vite';
import { folders, renderer, title, version } from './config/index.js';
function skipSourcemaps(paths: string[]): Plugin {
return {
name: 'skip-sourcemaps',
transform(code, id) {
if (paths.some((pkg) => id.includes(pkg))) {
return {
code: code,
// https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations
map: { mappings: '' },
};
}
},
};
}
const config: UserConfigFn = async ({ mode, command }) => {
const { defineConfig } = await import('vite');
const { default: tsconfigPaths } = await import('vite-tsconfig-paths');
const { default: svgr } = await import('vite-plugin-svgr');
const { default: favicons } = await import('@peterek/vite-plugin-favicons');
const { default: react } = await import('@vitejs/plugin-react-swc');
const { default: mkcert } = await import('vite-plugin-mkcert');
const { compression } = await import('vite-plugin-compression2');
const { nodePolyfills } = await import('vite-plugin-node-polyfills');
const isDev = mode === 'development';
const isProd = mode === 'production';
const isStage = mode === 'staging';
const commonPlugins = [
skipSourcemaps(['node_modules']),
tsconfigPaths(),
nodePolyfills({
include: ['buffer', 'events', 'crypto', 'stream'],
}),
];
return defineConfig({
mode: isStage ? 'production' : mode,
cacheDir: resolve(folders.cache, 'vite-renderer'),
base: '',
root: resolve(folders.rendererRoot, 'app'),
define: {
'process.env.PRODUCT_NAME': JSON.stringify(title),
'process.env.VERSION': JSON.stringify(version),
'process.env.BUILD_SOURCE': JSON.stringify(process.env.BUILD_SOURCE),
'process.env.CHAINS_FILE': JSON.stringify(process.env.CHAINS_FILE ?? 'chains'),
'process.env.TOKENS_FILE': JSON.stringify(process.env.TOKENS_FILE ?? 'tokens'),
'process.env.LOGGER': JSON.stringify(process.env.LOGGER),
},
worker: {
format: 'es',
plugins: () => commonPlugins,
},
build: {
sourcemap: isStage || undefined,
minify: !isDev,
outDir: folders.devBuild,
emptyOutDir: false,
target: 'es2021',
rollupOptions: {
treeshake: 'recommended',
maxParallelFileOps: Math.max(1, cpus().length - 1),
},
},
assetsInclude: ['**/*.wasm'],
server: {
// host: renderer.server.host,
port: renderer.server.port,
},
plugins: [
...commonPlugins,
command === 'serve' && mkcert(),
react({
plugins: !isProd ? [['@effector/swc-plugin', {}]] : [],
}),
svgr({
include: '**/*.svg?jsx',
esbuildOptions: { jsx: 'automatic' },
svgrOptions: {
plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
memo: true,
ref: true,
jsxRuntime: 'automatic',
svgo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: { overrides: { removeViewBox: false, cleanupIds: false } },
},
],
},
},
}),
favicons(
mode === 'development'
? resolve(folders.rendererRoot, 'app/favicon.dev.png')
: resolve(folders.rendererRoot, 'app/favicon.png'),
{
appName: 'Nova Spektr',
appShortName: 'Spektr',
appDescription:
'Enterprise desktop wallet for Polkadot supporting multisigs, staking, light clients and more',
icons: {
android: true,
appleIcon: true,
appleStartup: true,
favicons: true,
windows: true,
yandex: true,
},
},
),
isProd &&
command === 'build' &&
compression({
algorithm: 'gzip',
include: /.+/,
skipIfLargerOrEqual: true,
threshold: 0,
compressionOptions: {
level: 9,
},
}),
],
optimizeDeps: {
// .wasm module inside library get incorrect path when optimized by vite.
exclude: ['raptorq'],
},
});
};
export default config;