monaco-editor

访客4年前黑客文章1181

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

相关文章

宠物狗站立怎么训(狗狗训练站立方法过程)

宠物狗站立怎么训(狗狗训练站立方法过程)

若狗狗能学会“站立”动作,表示狗狗对于狗主人的一切要求指令,已有某种程度上的服从性。狗狗前腿离地,可用两只后腿着地,当它们学会站立后,您可以命令它们长时间的站立起来,这样狗狗为了找平衡会左右的走动,久...

渝记麻辣烫开一家多少钱?合理化的投资让大家轻松加盟

渝记麻辣烫开一家多少钱?合理化的投资让大家轻松加盟

近年来的餐饮行业的发展情况可以说是百花争艳,百家争鸣啊。多种多样的创业加盟品牌项目突然一夜之间犹如雨后春笋般的出现,让加盟商感到措手不及。为什么这样说呢?眼一分为二的来看,一方面可以有力更多的加盟品牌...

验孕棒使用方法(你会正确使用验孕棒吗)

验孕棒使用方法(你会正确使用验孕棒吗)一些小夫妻们进行正常的性生活,是我们生理的一种正常需要,但是在我们性生活之后,到了我们生理期的时候却迟迟不来,这时候一些女性朋友们都会使用验孕棒来测试我们是否怀孕...

曹衣出水形容哪种艺术?(“曹衣出水,吴带当风”,是一种怎样的境

  谈起吴道子,但凡掌握美术绘画的人都是会听闻过他的名字。他生在盛唐时期,是唐朝著名的画家。有着“画圣”之盛名,在他的一生中,关键活跃性于唐开元、天宝年间。针对他的美术绘画造就,后人一直称赞能加,除开...

中国将强化医疗服务体冬菇头系布局,“高峰”“高原

  我国将强化医疗服务体系布局,“高峰”“高原”“高地”并重   新华社北京12月14日电(记者陈聪、屈婷)国家卫生健康委员会医政医管局监察专员焦雅辉说,“十四五”期间要强化医疗服务体系布局,让国家...

米扑博客

米扑博客, 专注于IT手艺与量化金融, 用手艺缔造人生财富。   思源资源网:分类流动 1.阿里云: 本站现在使用的是阿里云主机,平安/可靠/稳固。点击领取2000米代金券、领会最新阿里云...