-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathvite.config.ts
More file actions
106 lines (103 loc) · 3.59 KB
/
vite.config.ts
File metadata and controls
106 lines (103 loc) · 3.59 KB
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
import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig } from "vite";
export default ({ mode }) => {
const isDev = mode === "development";
// In Dev, Resolve the SDK locally as src, not /dist so it can hot reload
// But for CSS files, we need to point to dist since they're only generated during build
const resolve = {
alias: {
// CSS files must come BEFORE the general SDK alias
"@malloy-publisher/sdk/styles.css": path.resolve(
__dirname,
"../sdk/dist/styles.css",
),
"@malloy-publisher/sdk/malloy-explorer.css": path.resolve(
__dirname,
"../sdk/dist/malloy-explorer.css",
),
"@malloy-publisher/sdk/markdown-editor.css": path.resolve(
__dirname,
"../sdk/dist/markdown-editor.css",
),
// Client subpath must come BEFORE the general SDK alias
"@malloy-publisher/sdk/client": isDev
? path.resolve(__dirname, "../sdk/src/client-entry.ts")
: path.resolve(__dirname, "../sdk/dist/client/index.es.js"),
"@malloy-publisher/sdk": isDev
? // General SDK alias for everything else
path.resolve(__dirname, "../sdk/src/index.ts")
: // In production, use the built SDK to avoid duplicate dependencies
path.resolve(__dirname, "../sdk/dist/index.es.js"),
},
};
// Disable chunking entirely to avoid initialization order issues
const manualChunks = undefined;
return defineConfig({
server: isDev
? {
proxy: {
"/api/v0": {
target: "http://localhost:4000",
changeOrigin: true,
},
},
}
: {},
plugins: [react()],
define: {
// This is REQUIRED for React and other libraries to eliminate debug code
"process.env.NODE_ENV": JSON.stringify(mode),
"process.env.NODE_DEBUG": "false",
// Custom defines for your own code (optional)
__DEV__: JSON.stringify(mode !== "production"),
__PROD__: JSON.stringify(mode === "production"),
},
build: {
minify: mode === "production",
sourcemap: mode !== "production",
emptyOutDir: true,
chunkSizeWarningLimit: 1000,
target: "esnext",
rollupOptions: {
onwarn(warning, warn) {
if (
warning.code === "MODULE_LEVEL_DIRECTIVE" ||
warning.code === "SOURCEMAP_ERROR"
) {
return;
}
warn(warning);
},
output: {
// Provide global variable names for externalized dependencies
globals: {
react: "React",
"react-dom": "ReactDOM",
"react/jsx-runtime": "ReactJSXRuntime",
"@emotion/react": "EmotionReact",
"@emotion/styled": "EmotionStyled",
"@mui/material": "MaterialUI",
"@mui/icons-material": "MaterialUIIcons",
"@mui/system": "MaterialUISystem",
},
manualChunks,
},
},
},
resolve,
// Optimize for faster builds
optimizeDeps: {
include: [
"react",
"react-dom",
"@emotion/react",
"@emotion/styled",
"@mui/material",
"@mui/icons-material",
"@mui/system",
],
exclude: [],
},
});
};