Skip to content

Commit

Permalink
fix(yaml) include yaml editor code in build. Avoid to rely on externa…
Browse files Browse the repository at this point in the history
…l domain cdn.jsdelivr.net to load editor code WD-9954

Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Mar 25, 2024
1 parent 5af14ce commit 5df2f22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"clean": "rm -rf node_modules yarn-error.log *.log build/ .jekyll-metadata .bundle playwright-report test-results haproxy-local.cfg coverage",
"build-html": "cp build/ui/index.html build/index.html",
"build": "npx vite build && yarn build-html",
"build-monaco": "mkdir build/ui/monaco-editor && cp -R node_modules/monaco-editor/min build/ui/monaco-editor",
"build": "npx vite build && yarn build-html && yarn build-monaco",
"format-js-eslint": "eslint 'src/**/*.{json,jsx,tsx,ts}' 'tests/**/*.ts' --fix",
"format-js-prettier": "prettier 'src/**/*.{json,jsx,tsx,ts}' 'tests/**/*.ts' --write",
"format-js": "yarn format-js-eslint && yarn format-js-prettier",
Expand Down
4 changes: 3 additions & 1 deletion src/components/forms/YamlForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, ReactNode, useEffect, useRef, useState } from "react";
import Editor from "@monaco-editor/react";
import Editor, { loader } from "@monaco-editor/react";
import { updateMaxHeight } from "util/updateMaxHeight";
import useEventListener from "@use-it/event-listener";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
Expand Down Expand Up @@ -28,6 +28,8 @@ const YamlForm: FC<Props> = ({
const [editor, setEditor] = useState<IStandaloneCodeEditor | null>(null);
const containerRef = useRef<HTMLDivElement>(null);

loader.config({ paths: { vs: "/ui/monaco-editor/min/vs" } });

const updateFormHeight = () => {
if (!editor || !containerRef.current) {
return;
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export default defineConfig({
rewrite: (path) => path.replace(/^\/ui/, ""),
secure: false,
},
"/ui/monaco-editor": {
target: "https://localhost:8407/node_modules",
rewrite: (path) => path.replace(/^\/ui/, ""),
secure: false,
},
},
},
build: {
Expand Down

0 comments on commit 5df2f22

Please sign in to comment.