-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.js
104 lines (91 loc) · 2.47 KB
/
vite.config.js
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
import path from "path";
import process from "process";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { nodePolyfills } from "vite-plugin-node-polyfills";
const host = process.env.TAURI_DEV_HOST;
function getBuildMode() {
if (process.env.BUILD_MODE) {
return process.env.BUILD_MODE;
}
const isTauri = process.env.TAURI_ENV_ARCH != undefined;
if (isTauri) {
return "tauri";
}
return "browser";
}
// https://vitejs.dev/config/
export default defineConfig(async () => {
/** @type {import('vite').UserConfig} */
const config = {
publicDir: "assets",
build: {
outDir: "public",
target: "safari13",
},
worker: {
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
plugins: [
react({
presets: [
[
"@babel/preset-env",
{ targets: "safari13", useBuiltins: "entry", corejs: "3.36" },
],
"@babel/preset-react",
],
// Use .babelrc files
babelrc: false,
// Use babel.config.js files
configFile: false,
}),
nodePolyfills(),
],
// 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,
// },
server: {
host: host || false, // listen on all addresses
port: 1420, // 4173 is a port for `vite preview` because `vite dev` fails on legacy mobile
strictPort: true,
hmr: host
? {
protocol: "ws",
// host: "192.168.1.3",
host,
port: 1430,
}
: undefined,
watch: {
// 3. tell vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
// TODO: check for build, https://github.com/vitejs/vite/issues/8427
// https://github.com/vitejs/vite/issues/11672
// optimizeDeps: { exclude: {} },
// 3. to make use of `TAURI_DEBUG` and other env variables
// https://tauri.app/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src/"),
},
},
define: {
__BUILD_MODE__: JSON.stringify(getBuildMode()),
},
};
return config;
});