-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
75 lines (67 loc) · 2.18 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
import { execSync } from "child_process";
import { defineConfig, loadEnv, resolvePackageData } from "vite";
import react from "@vitejs/plugin-react-swc";
import svgr from "vite-plugin-svgr";
import { GlitchTipPlugin } from "./vite/vite.plugins";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const { GLITCH_TIP_AUTH_TOKEN, GLITCH_TIP_ORG, GLITCH_TIP_PROJECT, GLITCH_TIP_URL } = loadEnv(
mode,
process.cwd(),
"GLITCH_TIP",
);
const packageJsonPath = resolvePackageData("bitmovinf-player", process.cwd());
if (packageJsonPath?.data) {
process.env.VITE_BITMOVIN_PLAYER_VERSION = packageJsonPath.data.version;
}
let glitchTipPlugin: GlitchTipPlugin | undefined = undefined;
if (
mode === "production" &&
GLITCH_TIP_AUTH_TOKEN != null &&
GLITCH_TIP_ORG != null &&
GLITCH_TIP_PROJECT != null &&
GLITCH_TIP_URL != null
) {
const commitHash = execSync("git rev-parse HEAD").toString().trimEnd();
glitchTipPlugin = new GlitchTipPlugin({
authToken: GLITCH_TIP_AUTH_TOKEN,
org: GLITCH_TIP_ORG,
project: GLITCH_TIP_PROJECT,
url: GLITCH_TIP_URL,
releaseName: commitHash,
});
}
return {
plugins: [react(), svgr(), glitchTipPlugin],
css: {
modules: {
localsConvention: "camelCaseOnly",
generateScopedName: mode === "development" ? "[name]__[local]___[hash:base64:5]" : undefined,
},
preprocessorOptions: {
scss: {
additionalData: `@import "src/styles/mixins.scss";`,
},
},
},
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks: (id) => {
const includes = (text: string, search: string) => text.indexOf(search) > 0;
if (includes(id, "node_modules/bitmovin-player") || includes(id, "node_modules/bitmovin-player-ui")) {
return "bitmovin";
}
if (includes(id, "node_modules/lottie-react") || includes(id, "node_modules/lottie-web")) {
return "lottie";
}
if (id.indexOf("node_modules") > 0) {
return "vendor";
}
},
},
},
},
};
});