diff --git a/.gitignore b/.gitignore index 367bc47e..68ac54d3 100755 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ coverage /release /out *.asar +/public/monaco # Editor directories and files .vscode/* diff --git a/components/TextEditorModal.tsx b/components/TextEditorModal.tsx index 4349c50c..f26b677b 100644 --- a/components/TextEditorModal.tsx +++ b/components/TextEditorModal.tsx @@ -12,7 +12,10 @@ import type * as Monaco from 'monaco-editor'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; // Configure Monaco to use local files instead of CDN -loader.config({ paths: { vs: './node_modules/monaco-editor/min/vs' } }); +const monacoBasePath = import.meta.env.DEV + ? './node_modules/monaco-editor/min/vs' + : `${import.meta.env.BASE_URL}monaco/vs`; +loader.config({ paths: { vs: monacoBasePath } }); import { useI18n } from '../application/i18n/I18nProvider'; import { getLanguageId, getLanguageName, getSupportedLanguages } from '../lib/sftpFileUtils'; diff --git a/package.json b/package.json index 3c46bae6..1167945f 100755 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "dev": "npm run lint && concurrently -k \"vite\" \"npm:dev:electron\"", "dev:electron": "wait-on http-get://localhost:5173 && cross-env VITE_DEV_SERVER_URL=http://localhost:5173 node electron/launch.cjs", + "prebuild": "node scripts/copy-monaco.cjs", "build": "vite build", "preview": "vite preview", "start": "node electron/launch.cjs", diff --git a/scripts/copy-monaco.cjs b/scripts/copy-monaco.cjs new file mode 100644 index 00000000..ba24c5ff --- /dev/null +++ b/scripts/copy-monaco.cjs @@ -0,0 +1,16 @@ +const fs = require('fs'); +const path = require('path'); + +const repoRoot = path.resolve(__dirname, '..'); +const source = path.join(repoRoot, 'node_modules', 'monaco-editor', 'min', 'vs'); +const target = path.join(repoRoot, 'public', 'monaco', 'vs'); + +if (!fs.existsSync(source)) { + console.error('[copy-monaco] Source not found:', source); + process.exit(1); +} + +fs.rmSync(target, { recursive: true, force: true }); +fs.mkdirSync(path.dirname(target), { recursive: true }); +fs.cpSync(source, target, { recursive: true }); +console.log('[copy-monaco] Copied Monaco VS assets to', target);