Skip to content

Commit 746326a

Browse files
committed
feat: self-host Monaco Editor assets instead of using CDN
Bundle Monaco Editor workers locally to avoid network issues in regions where CDN access may be restricted or unreliable. - Add monaco-editor and vite-plugin-monaco-editor dependencies - Configure Vite to bundle Monaco workers (editor, json, html, css) - Update loader config to use locally bundled Monaco instance
1 parent 0244f0e commit 746326a

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

frontend/bun.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@
1212
},
1313
"dependencies": {
1414
"@heroui/react": "^2.8.7",
15-
"@sentry/react": "^8.0.0",
1615
"@monaco-editor/react": "^4.7.0",
16+
"@sentry/react": "^8.0.0",
1717
"@tanstack/react-query": "^5.90.16",
1818
"axios": "^1.13.2",
1919
"clsx": "^2.1.1",
2020
"esbuild": "^0.27.2",
2121
"flag-icons": "^7.5.0",
2222
"framer-motion": "^12.26.1",
2323
"lucide-react": "^0.562.0",
24+
"monaco-editor": "^0.55.1",
2425
"react": "^19.2.0",
2526
"react-dom": "^19.2.0",
2627
"react-router-dom": "^7.12.0",
2728
"sonner": "^2.0.7",
2829
"tailwind-merge": "^3.4.0",
30+
"vite-plugin-monaco-editor": "^1.1.0",
2931
"zustand": "^5.0.10"
3032
},
3133
"devDependencies": {

frontend/src/main.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { BrowserRouter } from "react-router-dom";
77
import { Toaster } from "sonner";
88
import * as Sentry from "@sentry/react";
99
import { loader } from "@monaco-editor/react";
10+
import * as monaco from "monaco-editor";
1011
import App from "./App";
1112
import "./index.css";
1213
import "flag-icons/css/flag-icons.min.css";
1314

14-
// Configure and pre-initialize Monaco to prevent race conditions
15-
loader.config({
16-
"vs/nls": { availableLanguages: { "*": "en" } },
17-
});
15+
// Use locally bundled Monaco instead of CDN (jsdelivr is blocked in some regions)
16+
loader.config({ monaco });
1817

1918
// Pre-initialize Monaco - catches init errors at the source
2019
loader.init().catch(() => {

frontend/vite.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { defineConfig } from "vite";
22
import react from "@vitejs/plugin-react";
3+
import monacoEditorPluginModule from "vite-plugin-monaco-editor";
4+
/* eslint-disable @typescript-eslint/no-explicit-any -- CJS module interop varies by runtime */
5+
const monacoEditorPlugin: any =
6+
(monacoEditorPluginModule as any).default || monacoEditorPluginModule;
7+
/* eslint-enable @typescript-eslint/no-explicit-any */
38
import path from "path";
49

510
export default defineConfig({
6-
plugins: [react()],
11+
plugins: [
12+
react(),
13+
monacoEditorPlugin({
14+
// Only include the workers we need (editorWorkerService is required)
15+
languageWorkers: ["editorWorkerService", "json", "html", "css"],
16+
}),
17+
],
718
// Load .env from parent directory (shared with backend for local dev)
819
// In Docker builds, parent has no .env - Vite handles this gracefully
920
envDir: path.resolve(__dirname, ".."),

0 commit comments

Comments
 (0)