-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.ts
112 lines (108 loc) · 2.81 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
/// <reference types="vitest" />
import path from "node:path";
import { defineConfig, type UserConfig, type PluginOption } from "vite";
import react from "@vitejs/plugin-react-swc";
import yaml from "@modyfi/vite-plugin-yaml";
import Pages from "vite-plugin-pages";
import wasm from "vite-plugin-wasm";
import { visualizer } from "rollup-plugin-visualizer";
import { chunkSplitPlugin } from "vite-plugin-chunk-split";
import mdx from "@mdx-js/rollup";
// vite.config.js
const wasmContentTypePlugin = {
name: "wasm-content-type-plugin",
configureServer(server: any) {
server.middlewares.use((req: any, res: any, next: any) => {
if (req.url.endsWith(".wasm")) {
res.setHeader("Content-Type", "application/wasm");
}
next();
});
},
};
export default defineConfig(({ mode }) => {
// https://vitejs.dev/config/
const sharedConfig: UserConfig = {
resolve: {
alias: {
"~/": `${path.resolve(__dirname, "src")}/`,
},
},
build: {
chunkSizeWarningLimit: 700,
outDir: `dist/${mode.toLowerCase()}`,
emptyOutDir: true,
reportCompressedSize: false,
rollupOptions: {
treeshake: {
moduleSideEffects: "no-external",
},
},
},
esbuild: {
supported: {
"top-level-await": true,
},
},
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
optimizeDeps: {
exclude: ["libchai"],
},
plugins: [
wasmContentTypePlugin,
{ enforce: "pre", ...mdx() },
react({
// plugins: [["@swc-jotai/react-refresh", {}]],
}),
wasm(),
yaml(),
Pages({
importMode: "async",
}),
chunkSplitPlugin({
customSplitting: {
lodash: [/node_modules\/lodash/],
antd: [/node_modules\/antd/],
router: [/node_modules\/react-router/],
react: [/node_modules\/react(-dom)?\//],
immer: [/node_modules\/immer/],
//mathjs: [/node_modules\/mathjs/],
yaml: [/node_modules\/js-yaml/],
reactflow: [/node_modules\/@reactflow/],
//chart: [/node_modules\/@ant-design/],
//antv: [/node_modules\/@antv/],
tools: [/node_modules\/styled-components/, /node_modules\/js-md5/],
},
}),
],
test: {
globals: true,
coverage: {
enabled: true,
provider: "v8",
reporter: ["text", "html"],
},
},
worker: {
format: "es",
},
};
switch (mode) {
case "CF":
break;
case "BEX":
sharedConfig.plugins?.push(
visualizer({
brotliSize: true,
title: "打包产物分析",
filename: "dist/visualizer.html",
}) as PluginOption,
);
break;
case "PAGES":
break;
}
return sharedConfig;
});