-
Notifications
You must be signed in to change notification settings - Fork 6
/
vite.config.ts
115 lines (103 loc) · 2.89 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
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
import { networkInterfaces } from "os";
import * as path from "path";
import { Plugin, UserConfig, searchForWorkspaceRoot } from "vite";
import ifdef from "vite-plugin-conditional-compiler";
import { nodePolyfills as polyfills } from "vite-plugin-node-polyfills";
import env from "./scripts/compileTimeEnv.mjs";
import ViteSourceMapUploader from "./scripts/sourceMaps/ViteSourceMapUploader.mjs";
const { getBuiltInVariables } = env;
if (!process.env.VITE_ENVIRONMENT) process.env.VITE_ENVIRONMENT = "next";
const isProduction = process.env.PRODUCTION === "true";
const ipv4 = networkInterfaces()?.en0?.[1]?.address ?? "localhost";
// https://github.com/vitejs/vite/issues/15012
const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => {
return {
name: "mute-warnings",
enforce: "pre",
config: (userConfig) => ({
build: {
rollupOptions: {
onwarn(warning, defaultHandler) {
if (warning.code) {
const muted = warningsToIgnore.find(
([code, message]) => code == warning.code && warning.message.includes(message),
);
if (muted) return;
}
if (userConfig.build?.rollupOptions?.onwarn) {
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
} else {
defaultHandler(warning);
}
},
},
},
}),
};
};
export default (): UserConfig => ({
cacheDir: ".vite-cache",
logLevel: "info",
appType: "spa",
plugins: [
muteWarningsPlugin([
["MODULE_LEVEL_DIRECTIVE", `"use-client"`],
["EVAL", "Use of eval"],
]),
ifdef(),
polyfills({
protocolImports: true,
exclude: ["buffer"],
}),
isProduction && ViteSourceMapUploader(),
],
clearScreen: false,
resolve: {
alias: {
"@components": path.resolve(__dirname, "core/components"),
"@core": path.resolve(__dirname, "core/logic"),
"@core-ui": path.resolve(__dirname, "core/ui-logic"),
"@ext": path.resolve(__dirname, "core/extensions"),
"@app": path.resolve(__dirname, "app"),
"@services": path.resolve(__dirname, "services/core"),
"fs-extra": path.resolve(__dirname, "core/logic/FileProvider/DiskFileProvider/DFPIntermediateCommands.ts"),
},
},
server: {
sourcemapIgnoreList: (path) => path.includes("node_modules"),
open: false,
host: "localhost",
port: 5173,
strictPort: true,
hmr: {
protocol: "ws",
host: ipv4,
port: 5174,
},
fs: {
allow: [path.join(searchForWorkspaceRoot(process.cwd(), "../../"))],
},
},
define: {
"process.version": [], // https://github.com/browserify/browserify-sign/issues/85
"process.builtIn": getBuiltInVariables(),
"process.env.NODE_DEBUG": false,
},
publicDir: "./core/public",
envPrefix: ["VITE", "TAURI", "GX"],
worker: {
format: "es",
},
build: {
target: "esnext",
emptyOutDir: true,
modulePreload: true,
chunkSizeWarningLimit: 5000,
outDir: "dist",
rollupOptions: {
external: ["fsevents"],
},
minify: true,
sourcemap: isProduction,
},
});