All Projects → suren-atoyan → monaco-loader

suren-atoyan / monaco-loader

Licence: MIT license
The utility to easy setup monaco-editor into your browser

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to monaco-loader

Apubplat
Devops自动化部署、堡垒机开源项目、Web Terminal
Stars: ✭ 167 (+96.47%)
Mutual labels:  monaco-editor
ZSpider
基于Electron爬虫程序
Stars: ✭ 37 (-56.47%)
Mutual labels:  monaco-editor
monaco-editor-esm-webpack-plugin
No description or website provided.
Stars: ✭ 25 (-70.59%)
Mutual labels:  monaco-editor
React Monaco Editor
Monaco Editor for React.
Stars: ✭ 2,536 (+2883.53%)
Mutual labels:  monaco-editor
monaco-editor-custom-intellisense
Code from the "Custom IntelliSense with Monaco Editor" post
Stars: ✭ 23 (-72.94%)
Mutual labels:  monaco-editor
Operational-Transformation
A collection of Algorithms to Synchronise changes across multiple clients using Operational Transformation
Stars: ✭ 25 (-70.59%)
Mutual labels:  monaco-editor
Monaco Vim
VIM keybindings for monaco editor
Stars: ✭ 131 (+54.12%)
Mutual labels:  monaco-editor
ovid-editor
Adobe panel providing the most advanced scripting environment possible -- Typescript, app DOM autocomplete, full I/O features and more
Stars: ✭ 43 (-49.41%)
Mutual labels:  monaco-editor
mongood
A MongoDB GUI with Fluent Design
Stars: ✭ 674 (+692.94%)
Mutual labels:  monaco-editor
emmet-monaco
Emmet support for monaco-editor
Stars: ✭ 19 (-77.65%)
Mutual labels:  monaco-editor
Vue Monaco Editor
Monaco Editor Vue Component
Stars: ✭ 187 (+120%)
Mutual labels:  monaco-editor
constrained-editor-plugin
This project is to restrict the editable area in the monaco-editor
Stars: ✭ 55 (-35.29%)
Mutual labels:  monaco-editor
sprite
🖌 Draw charts in code. Render in real-time. Embed anywhere as .png.
Stars: ✭ 202 (+137.65%)
Mutual labels:  monaco-editor
Web Code
A text editor for the web based around monaco
Stars: ✭ 174 (+104.71%)
Mutual labels:  monaco-editor
react-monacoeditor
Monaco Editor component for React.
Stars: ✭ 191 (+124.71%)
Mutual labels:  monaco-editor
Yn
Yank Note 一款面向程序员的 Markdown 笔记应用。支持加密文档,代码片段运行,内置终端,图表嵌入,HTML 小工具。
Stars: ✭ 143 (+68.24%)
Mutual labels:  monaco-editor
V2releases
A friendly ARM assembler and simulator for educational use
Stars: ✭ 46 (-45.88%)
Mutual labels:  monaco-editor
Blazaco
A Blazor Component utilizing the Monaco editor by Microsoft
Stars: ✭ 23 (-72.94%)
Mutual labels:  monaco-editor
wiql-editor
Search work items with wiql queries.
Stars: ✭ 30 (-64.71%)
Mutual labels:  monaco-editor
bundle
An online tool to quickly bundle & minify your projects, while viewing the compressed gzip/brotli bundle size, all running locally on your browser.
Stars: ✭ 475 (+458.82%)
Mutual labels:  monaco-editor

@monaco-editor/loader · monthly downloads gitHub license npm version PRs welcome

The utility to easy setup monaco-editor into your browser

Synopsis

Configure and download monaco sources via its loader script, without needing to use webpack's (or any other module bundler's) configuration files

Motivation

It's been a while we are working with monaco editor. It's a great library and provides a powerful editor out of the box. Anyway, there were couple of problems related to the setup process. The main problem is the need to do some additional webpack configuration; that's not bad, but some quite useful tools, like CRA, aren't happy with that fact. The library @monaco-editor/react was being created to solve that problem - monaco editor wrapper for easy/one-line integration with React applications without needing to use webpack's (or any other module bundler's) configuration files. In that library, there was a utility that cares about the initialization process of monaco and overcomes the additional use of webpack configuration. That utility grows over time and now it's a separate library. Now, you can easily setup monaco into your browser, create your own editors, wrappers for React/Vue/Angular of whatever you want.

How it works

Monaco editor provides a script called loader, which itself provides tooling to download monaco sources. The library, under the hood, handles the configuration and loading part and gives us an easy-to-use API to interact with it

Documentation

Contents

Installation

npm install @monaco-editor/loader

or

yarn add @monaco-editor/loader

NOTE: For TypeScript type definitions, this package uses the monaco-editor package as a peer dependency. So, if you need types and don't already have the monaco-editor package installed, you will need to do so.

Introduction

The library exports types and the utility called loader, the last one has two methods

Usage

import loader from '@monaco-editor/loader';

loader.init().then(monaco => {
  monaco.editor.create(/* editor container, e.g. document.body */, {
    value: '// some comment',
    language: 'javascript',
  });
});

codesandbox

.config

By using the .config method we can configure the monaco loader. By default all sources come from CDN, you can change that behavior and load them from wherever you want

import loader from '@monaco-editor/loader';

// you can change the source of the monaco files
loader.config({ paths: { vs: '...' } });

// you can configure the locales
loader.config({ 'vs/nls': { availableLanguages: { '*': 'de' } } });

// or
loader.config({
  paths: {
    vs: '...',
  },
  'vs/nls' : {
    availableLanguages: {
      '*': 'de',
    },
  },
});

loader.init().then(monaco => { /* ... */ });

codesandbox

Configure the loader to load the monaco as an npm package

import loader from '@monaco-editor/loader';
import * as monaco from 'monaco-editor';

loader.config({ monaco });

loader.init().then(monacoInstance => { /* ... */ });

codesandbox

.init

The .init method handles the initialization process. It returns the monaco instance, wrapped with cancelable promise

import loader from '@monaco-editor/loader';

loader.init().then(monaco => {
  console.log('Here is the monaco instance', monaco);
});

codesandbox

import loader from '@monaco-editor/loader';

const cancelable = loader.init();

cancelable.then(monaco => {
  console.log('You will not see it, as it is canceled');
});

cancelable.cancel();

codesandbox

Notes

For electron users

In general it works fine with electron, but there are several cases that developers usually face to and sometimes it can be confusing. Here they are:

  1. Download process fails or if you use @monaco-editor/react You see loading screen stuck Usually, it's because your environment doesn't allow you to load external sources. By default, it loads monaco sources from CDN. You can see the default configuration. But sure you can change that behavior; the library is fully configurable. Read about it here. So, if you want to download it from your local files, you can do it like this:
import loader from '@monaco-editor/loader';

loader.config({ paths: { vs: '../path-to-monaco' } });

or, if you want to use it as an npm package, you can do it like this:

import loader from '@monaco-editor/loader';
import * as monaco from 'monaco-editor';

loader.config({ monaco });

loader.init().then(monacoInstance => { /* ... */ });
  1. Based on your electron environment it can be required to have an absolute URL The utility function taken from here can help you to achieve that. Let's imagine you have monaco-editor package installed and you want to load monaco from the node_modules rather than from CDN: in that case, you can write something like this:
function ensureFirstBackSlash(str) {
    return str.length > 0 && str.charAt(0) !== '/'
        ? '/' + str
        : str;
}

function uriFromPath(_path) {
    const pathName = path.resolve(_path).replace(/\\/g, '/');
    return encodeURI('file://' + ensureFirstBackSlash(pathName));
}

loader.config({
  paths: {
    vs: uriFromPath(
      path.join(__dirname, '../node_modules/monaco-editor/min/vs')
    )
  }
});

or, just use it as an npm package.

There were several issues about this topic that can be helpful too - 1 2 3 4

And if you use electron with monaco and have faced an issue different than the above-discribed ones, please let us know to make this section more helpful.

For Next.js users

The part of the source that should be pre-parsed is optimized for server-side rendering, so, in usual cases, it will work fine, but if you want to have access, for example, to monacoInstance you should be aware that it wants to access the document object, and it requires browser environment. Basically you just need to avoid running that part out of browser environment, there are several ways to do that. One of them is described here.

And if you use monaco with Next.js and have faced an issue different than the above-described one, please let us know to make this section more helpful.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].