-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
94 lines (85 loc) · 2.58 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
/// <reference types="vitest" />
import path from "path";
import { PluginOption, UserConfig, defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import eslint from "vite-plugin-eslint";
import { coverageConfigDefaults } from "vitest/config";
import dts from "vite-plugin-dts";
// TODO: remove extra compile step when vscode can run esmodules https://github.com/microsoft/vscode/issues/130367
// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
function makeConfig(library: "browser" | "node") {
return defineConfig(({ command, mode }) => {
const OUT_DIR = library === "browser" ? "dist/chat" : "dist/events";
const CONFIG: UserConfig = {
// Build the webpage
define: {
"process.env.NODE_ENV": JSON.stringify(mode),
},
mode,
build: {
emptyOutDir: true,
outDir: OUT_DIR,
copyPublicDir: false,
sourcemap: library === "browser" ? "inline" : false,
rollupOptions: {
// TODO: remove when this issue is closed https://github.com/vitejs/vite/issues/15012
onwarn(warning, defaultHandler) {
if (warning.code === "SOURCEMAP_ERROR") {
return;
}
defaultHandler(warning);
},
},
},
plugins: [react()],
server: {
proxy: {
"/v1": process.env.REFACT_LSP_URL ?? "http://127.0.0.1:8001",
},
},
test: {
retry: 2,
environment: "jsdom",
coverage: {
exclude: coverageConfigDefaults.exclude.concat(
"**/*.stories.@(js|jsx|mjs|ts|tsx)",
),
},
setupFiles: ["./src/utils/test-setup.ts"],
},
css: {
modules: {},
},
};
if (command !== "serve") {
CONFIG.mode = "production";
CONFIG.define = { "process.env.NODE_ENV": "'production'" };
CONFIG.plugins?.push([
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
eslint() as PluginOption,
]);
CONFIG.plugins?.push([
dts({
outDir: OUT_DIR,
rollupTypes: true,
insertTypesEntry: true,
}),
]);
CONFIG.build = {
...CONFIG.build,
lib: {
entry:
library === "browser"
? path.resolve(__dirname, "src/lib/index.ts")
: path.resolve(__dirname, "src/events/index.ts"),
name: "RefactChat",
fileName: "index",
},
};
}
return CONFIG;
});
}
export default makeConfig("browser");
export const nodeConfig = makeConfig("node");