-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to import this library in a create-react-app? #82
Comments
An old issue, but with a lot of thumbs up. Someone has done the work of wrapping the monaco editor in a react component: https://www.npmjs.com/package/@types/react-monaco-editor Note that there are some issues with this implementation. To make it work myself, I included
in the Good luck. I had more trouble than I expected setting this up, but it's going swimmingly now. |
@NiloCK you saved me from giving up! Thanks! |
Now that monaco supports esm modules (thanks!), i was really hoping i'll be able to use the monaco-editor npm package in a create-react-app application (since the later is using webpack under the hood). Unfortunately, monaco-editor-smpale seem to suggest i need to configure webpack with plugins, which is not possible in create-react-app without ejecting. Did anyone successfully import monaco-editor package in create-react-app without ejecting and without doing weird stuff like loading monaco's loader.js? |
Bump. |
I stumbled upon the issue of getting Monaco up and running with https://medium.com/@haugboelle/short-guide-to-using-monaco-with-create-react-app-26a1acad8ebe |
Hope Microsoft release |
@kasperpeulen, after tried a lot of method mentioned here, I found a elegant way by replace
The full functional demo can be found on https://github.com/liudonghua123/create-react-app-monaco-editor |
I use it this way. seems working fine currently.. (copy
|
I think it will help you guys. I faced this issue about 2 years ago. I wrote a wrapper, for monaco to use it with an application powered by create-react-app. And use that solution in many projects. Now I publish it. Basically, it’s a monaco editor wrapper for painless integration with React applications without the need of webpack (or another module bundler) configuration files. |
For anyone wanting to use the JS-only: npx create-react-app --scripts-version=@bitauth/react-scripts-bitauth-ide my-app Typescript: npx create-react-app --typescript --scripts-version=@bitauth/react-scripts-bitauth-ide my-app And you can see an example of it working with a custom theme, custom language, range markers (underlining errors), hover providers, and autocompletion providers in bitauth-ide. |
This is the cleanest setup I was able to come up with. It's not ideal since Monaco is now outside of <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs/editor/editor.main.css">
</head>
<body>
<div id="root"></div>
<script>var require={paths:{'vs':'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs'}};</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs/loader.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs/editor/editor.main.nls.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs/editor/editor.main.js"></script>
</body>
</html> Then import React from 'react'
export default function Monaco({ config, onEditor }) {
const elem = React.useRef()
const monaco = React.useRef(window.monaco)
const [editor, setEditor] = React.useState()
React.useEffect(() => {
if (elem.current && monaco.current && !editor) {
const newEditor = monaco.current.editor.create(elem.current, config)
setEditor(newEditor)
}
}, [config, elem, monaco, editor])
React.useEffect(() => {
if (editor) {
onEditor?.(editor)
}
}, [editor, onEditor])
return <div ref={elem} />
} |
So I stumbled on this post in search of a way to get syntax highlighting and autocomplete working with Monaco Editor. I tried a few of the solutions above and was not satisfied with the result. So I took a different approach....
/* package.json */
"scripts": {
// "start": "react-scripts start",
"start": "react-app-rewired start",
// "build": "react-scripts build",
"build": "react-app-rewired build",
// "test": "react-scripts test --env=jsdom",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject" // dont change eject
}
/* config-overrides.js */
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = function override(config, env) {
config.plugins = [
...config.plugins,
new MonacoWebpackPlugin()
]
return config;
} Syntax highlighting and auto complete now works. I hope this helps someone out there 🎉 |
See microsoft/monaco-editor#82 We copy it locally and then hack the loader to load it
Yet another update of @monaco-editor/react |
Add support for Julia
…slist-4.16.6 Bump browserslist from 4.16.3 to 4.16.6
I'm able to use monaco 0.30.1 in a CRA app without using
I did try adding |
thank u so much!!!! |
Trying to bundle monaco editor into my app using react-app-rewired and webpack. When trying to deploy to disconnected environment - I'm getting 404 on the file: https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.js When I deploy to an environment which is connected to the internet, I see all the files are pulled from jsdelivr and not from my bundle. Here is my configuration of config-overrides.js:
|
After a lot of testing and playing around this was the ultimate answer, which I was looking for: #2605 (comment)
import Editor, { loader } from '@monaco-editor/react';
window.MonacoEnvironment = {
getWorker(moduleId, label): Promise<Worker> | Worker {
// see linked comment
},
};
loader.config({ monaco });
const MonacoEditorFactory: React.FC = () => {
return <Editor />;
} const MonacoEditorFactory = React.lazy(() => import('controls/monaco-editor/DummyMonaco'));
export const MonacoEditor: React.FC = () => {
return (
<div>
<React.Suspense fallback={<span>Loading...</span>}>
<MonacoEditorFactory />
</React.Suspense>
</div>
);
} |
We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider. If you wonder what we are up to, please see our roadmap and issue reporting guidelines. Thanks for your understanding, and happy coding! |
What about updating the webpack samples? Knowing that one can use |
We'd be open for a PR! We got the webpack examples as community contribution and are no webpack experts ourselves. |
I'm using from https://github.com/facebookincubator/create-react-app:
So far, I haven't had problems importing npm modules with the following syntax:
import _ from 'lodash'
However, I couldn't get this library to work in this setup. This seems like a super powerful editor, just can not get it to work.
The text was updated successfully, but these errors were encountered: