forked from microsoft/monaco-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#2767 from activeguild/add-vite-react-sample
Add 'browser-ems-vite-react' sample
- Loading branch information
Showing
11 changed files
with
992 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
src/**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>browser-esm-vite-react</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
874 changes: 874 additions & 0 deletions
874
monaco-editor-samples/browser-esm-vite-react/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "browser-esm-vite-react", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"serve": "vite preview" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"monaco-editor": "^0.30.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.0", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@vitejs/plugin-react": "^1.0.0", | ||
"typescript": "^4.4.4", | ||
"vite": "^2.6.14" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
monaco-editor-samples/browser-esm-vite-react/src/components/Editor.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Editor { | ||
width: 100vw; | ||
height: 100vh; | ||
} |
24 changes: 24 additions & 0 deletions
24
monaco-editor-samples/browser-esm-vite-react/src/components/Editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { VFC, useRef, useState, useEffect } from "react"; | ||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api"; | ||
import styles from "./Editor.module.css"; | ||
|
||
export const Editor: VFC = () => { | ||
const [editor, setEditor] = | ||
useState<monaco.editor.IStandaloneCodeEditor | null>(null); | ||
const monacoEl = useRef(null); | ||
|
||
useEffect(() => { | ||
if (monacoEl && !editor) { | ||
setEditor( | ||
monaco.editor.create(monacoEl.current!, { | ||
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'), | ||
language: "typescript", | ||
}) | ||
); | ||
} | ||
|
||
return () => editor?.dispose(); | ||
}, [monacoEl.current]); | ||
|
||
return <div className={styles.Editor} ref={monacoEl}></div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import {Editor} from './components/Editor' | ||
import "./userWorker"; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<Editor /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
) |
27 changes: 27 additions & 0 deletions
27
monaco-editor-samples/browser-esm-vite-react/src/userWorker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as monaco from "monaco-editor"; | ||
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; | ||
import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker"; | ||
import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker"; | ||
import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker"; | ||
import tsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker"; | ||
|
||
// @ts-ignore | ||
self.MonacoEnvironment = { | ||
getWorker(_: any, label: string) { | ||
if (label === "json") { | ||
return new jsonWorker(); | ||
} | ||
if (label === "css" || label === "scss" || label === "less") { | ||
return new cssWorker(); | ||
} | ||
if (label === "html" || label === "handlebars" || label === "razor") { | ||
return new htmlWorker(); | ||
} | ||
if (label === "typescript" || label === "javascript") { | ||
return new tsWorker(); | ||
} | ||
return new editorWorker(); | ||
}, | ||
}; | ||
|
||
monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
11 changes: 11 additions & 0 deletions
11
monaco-editor-samples/browser-esm-vite-react/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"strict": true, | ||
"module": "ESNext", | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["./src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()] | ||
}) |