-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
59 lines (56 loc) · 1.71 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
import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import path from 'node:path';
/**
* The production build breaks without this. I have no clue why. I tried googling it, 0 results found.
* Nothing in the docs. Is it Vite's Fault? Tauri's? Some random dependancy? I don't know.
* This works though - in both minified and non-minified builds. So yeah...
* The workaround is literally just adding another if check to prevent an error
*/
function getCustomNoNullDefaultsPlugin(): Plugin {
return {
name: 'no-defaults',
transform(code, _id, _options) {
return {
code: code.replace(
/typeof (.*) === "object" && typeof (.*)\.exports === "object"/g,
`typeof $1 === "object" && typeof $1.exports === "object" && $1.exports.default`,
),
};
},
};
}
// https://vitejs.dev/config/
export default defineConfig(async () => ({
plugins: [
react(),
eslint(),
nodePolyfills({
include: ['process'],
}),
getCustomNoNullDefaultsPlugin(),
],
build: {
minify: true,
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html'),
splashscreen: path.resolve(__dirname, 'splashscreen.html'),
},
},
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ['VITE_', 'TAURI_'],
}));