-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
67 lines (64 loc) · 2.13 KB
/
Copy pathvite.config.ts
File metadata and controls
67 lines (64 loc) · 2.13 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
import { ConfigEnv, defineConfig, loadEnv, UserConfig } from "vite";
import path from "path";
import { wrapperEnv } from "./build/utils";
import { createVitePlugins } from "./build/vite/plugin";
import { exclude, include } from "./build/vite/optimizer";
import { createBbsGateway, ensureCsrfCookie } from "./server/bbsGateway";
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
const env = loadEnv(mode, root);
const serverEnv = loadEnv(mode, root, "");
const viteEnv = wrapperEnv(env);
const isBuild = command === "build";
const bassRepo = path.resolve(serverEnv.BASS_REPO || process.env.BASS_REPO || path.resolve(root, "..", "Bass"));
const bbsSdkSource = path.join(bassRepo, "common/proto/gen-sdk/typescript-fetch/bff_bbs/src");
const bbsBffUrl = new URL(serverEnv.BBS_BFF_URL || "http://127.0.0.1:8001/");
const { VITE_DROP_CONSOLE } = viteEnv;
return {
root,
resolve: {
alias: {
"~": path.resolve(__dirname, "./components"),
"@": path.resolve(__dirname, "./"),
"#": path.resolve(__dirname, "./types"),
"@bass/bbs-sdk-fetch": bbsSdkSource,
},
},
server: {
host: true,
strictPort: false,
open: false,
cors: true,
hmr: true,
allowedHosts: true,
fs: {
allow: [root, bassRepo],
},
watch: {
ignored: ["!**/common/proto/gen-sdk/typescript-fetch/bff_bbs/src/**"],
},
},
esbuild: {
drop: VITE_DROP_CONSOLE ? ["console", "debugger"] : [],
},
// Browser and SSR rendering libraries are emitted into dist/server instead of
// duplicated in the runtime image's node_modules.
ssr: {
noExternal: ["lottie-web", "vditor"],
},
plugins: [
...createVitePlugins(viteEnv, isBuild),
{
name: "treble-bbs-session-gateway",
configureServer(server) {
server.middlewares.use(ensureCsrfCookie(false));
server.middlewares.use("/api/bbs", createBbsGateway({ bffUrl: bbsBffUrl.toString(), isProduction: false }));
},
},
],
optimizeDeps: {
include,
exclude,
},
};
});