Skip to content

Commit 4aeadb9

Browse files
committed
chore: implement manual chunks, make sentry a dynamic import
1 parent 71821e3 commit 4aeadb9

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

frontend/src/ts/sentry.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import * as Sentry from "@sentry/browser";
21
import { envConfig } from "./constants/env-config";
32

3+
async function getSentry(): Promise<typeof import("@sentry/browser")> {
4+
return await import("@sentry/browser");
5+
}
6+
47
let debug = false;
58

69
let activated = false;
710

8-
export function activateSentry(): void {
11+
export async function activateSentry(): Promise<void> {
912
if (activated) {
1013
console.warn("Sentry already activated");
1114
return;
1215
}
1316
activated = true;
1417
console.log("Activating Sentry");
18+
19+
const Sentry = await getSentry();
1520
Sentry.init({
1621
release: envConfig.clientVersion,
1722
dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688",
@@ -105,18 +110,24 @@ export function activateSentry(): void {
105110
});
106111
}
107112

108-
export function setUser(uid: string, name: string): void {
113+
export async function setUser(uid: string, name: string): Promise<void> {
114+
if (!activated) return;
115+
const Sentry = await getSentry();
109116
Sentry.setUser({
110117
id: uid,
111118
username: name,
112119
});
113120
}
114121

115-
export function clearUser(): void {
122+
export async function clearUser(): Promise<void> {
123+
if (!activated) return;
124+
const Sentry = await getSentry();
116125
Sentry.setUser(null);
117126
}
118127

119-
export function captureException(error: Error): void {
128+
export async function captureException(error: Error): Promise<void> {
129+
if (!activated) return;
130+
const Sentry = await getSentry();
120131
Sentry.captureException(error);
121132
}
122133

frontend/vite.config.prod.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { generatePreviewFonts } from "./scripts/font-preview";
44
import { VitePWA } from "vite-plugin-pwa";
55
import replace from "vite-plugin-filter-replace";
66
import path from "node:path";
7-
import { splitVendorChunkPlugin } from "vite";
87
import childProcess from "child_process";
98
import { checker } from "vite-plugin-checker";
109
import { writeFileSync } from "fs";
@@ -87,7 +86,6 @@ export default {
8786
tsconfigPath: path.resolve(__dirname, "./tsconfig.json"),
8887
},
8988
}),
90-
splitVendorChunkPlugin(),
9189
ViteMinifyPlugin({}),
9290
VitePWA({
9391
// injectRegister: "networkfirst",
@@ -282,6 +280,23 @@ export default {
282280
},
283281
chunkFileNames: "js/[name].[hash].js",
284282
entryFileNames: "js/[name].[hash].js",
283+
manualChunks: (id) => {
284+
if (id.includes("@sentry")) {
285+
return "vendor-sentry";
286+
}
287+
if (id.includes("jquery")) {
288+
return "vendor-jquery";
289+
}
290+
if (id.includes("@firebase")) {
291+
return "vendor-firebase";
292+
}
293+
if (id.includes("monkeytype/packages")) {
294+
return "monkeytype-packages";
295+
}
296+
if (id.includes("node_modules")) {
297+
return "vendor";
298+
}
299+
},
285300
},
286301
},
287302
},

0 commit comments

Comments
 (0)