monaco-editor

访客4年前黑客文章1180

Momonaco-editor是微软提供的代码编辑器,vscode即是使用它作为编辑器。它的开发语言是ts,可以嵌入到浏览器中。


安装

npm install monaco-editor复制代码

引用

本人写Vue + Webpack 较多,以此为例:

之一种写法: 使用  monaco-editor-webpack-plugin

// .vue 对应的 script剧本中
import * as monaco from 'monaco-editor';

monaco.editor.create(document.getElementById('container'), {
  value: [
    'function x() {',
    '\tconsole.log("Hello world!");',
    '}'
  ].join('\n'),
  language: 'javascript'
});
// 在 webpack.base.conf.js 中
// 需要安装 monaco-editor-webpack-plugin

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require('path');
module.exports = {
  ...
  plugins: [
    new MonacoWebpackPlugin()
  ]
};

第二种写法:

// .vue 对应的 script剧本中

import * as monaco from 'monaco-editor';

// Since packaging is done by you, you need
// to instruct the editor how you named the
// bundles that contain the web workers.
self.MonacoEnvironment = {
  getWorkerUrl: function (moduleId, label) {
    if (label === 'json') {
      return './json.worker.bundle.js';
    }
    if (label === 'css') {
      return './css.worker.bundle.js';
    }
    if (label === 'html') {
      return './html.worker.bundle.js';
    }
    if (label === 'typescript' || label === 'javascript') {
      return './ts.worker.bundle.js';
    }
    return './editor.worker.bundle.js';
  }
}

monaco.editor.create(document.getElementById('container'), {
  value: [
    'function x() {',
    '\tconsole.log("Hello world!");',
    '}'
  ].join('\n'),
  language: 'javascript'
});
// 在 webpack.base.conf.js 中
// 不需要安装任何剧本const path = require('path');

module.exports = {
  entry: {
    "app": './index.js',
    // Package each language's worker and give these filenames in `getWorkerUrl`
    "editor.worker": 'monaco-editor/e *** /vs/editor/editor.worker.js',
    "json.worker": 'monaco-editor/e *** /vs/language/json/json.worker',
    "css.worker": 'monaco-editor/e *** /vs/language/css/css.worker',
    "html.worker": 'monaco-editor/e *** /vs/language/html/html.worker',
    "ts.worker": 'monaco-editor/e *** /vs/language/typescript/ts.worker',
  },
  ...
};
返回列表

上一篇:RemoveBG

下一篇:progress.js

相关文章

如何可以监控老公的电话

    今天本文主要给大家分享一则vivo手机微信删除的聊天记...

冰晶石是什么化合物?冰晶石的作用和用途有哪

冰晶石是什么化合物?冰晶石的作用和用途有哪

分子式:Na3AlF6 分子量:209.94 执行标准: GB 4291-2007 危险级别: 6.1 商品编码:2826.3000 物化性质: 无色单斜晶系晶体,常因含杂质而呈灰白色...

汾酒杏花村加盟费多少

  山西汾酒署理加盟   不知你在什么区域,假如是署理汾酒的话,大概条件较量高一些,不外我以为你可以署理杏花村系列产物,这个系列产物价值较量低一些.   汾酒署理需要几多钱,汾酒署理需要几多钱,汾酒署...

新型SEO技术是什么?新型SEO内容包括哪些?

新型SEO技术是什么?新型SEO内容包括哪些?

对于搜索引擎而言,每天都在修正相关的算法,其核心的目的就是,精准的识别优质的能够解决用户搜索需求的内容。并且,搜索引擎在不断的去SEO优化技术指标,但这并不代表新型SEO优化技术,在网站优化的过程...

第一次打开网站点击任意跳转指定网址

首先设置一个div层 以及css <div id="firstMask" style="display: none;"></div> <style type="tex...

专业找手机黑客(黑客属于什么专业)

嗯。大体应该是计算机专业。细一点的话,网络技术,软件设计等等……怎么说呢,其实你要只学这一个专业的话,都是成不了太高水平的黑客。不过硬要选。 楼主我觉得你想了解更多这方面的问题可以选择专业的地方:黑客...