@codingame/monaco-editor-wrapper

中文文档
36.0.0发布于 2026/11/06TypeScriptES Module构建来源已验证近 30 天下载 4923

Configured monaco-vscode-api with tools and extensions

原始使用文档
文档目录4 节
  1. Synopsis
  2. Installation
  3. Usage
  4. Embed language IntelliSense

@codingame/monaco-editor-wrapper · monthly downloads npm version PRs welcome

Synopsis

Monaco editor wrapper uses and configures monaco-vscode-api for you

It also includes some tools allowing to add some missing features to monaco-editor:

  • preventAlwaysConsumeTouchEvent, mobile feature corresponding to the alwaysConsumeMouseWheel monaco-editor option
  • collapseCodeSectionsFromRanges allows to create and collapse a code section
  • collapseCodeSections allows to create and collapse a code section between 2 tokens
  • registerTextDecorationProvider allows to compute decorations on all existing editors
  • hideCodeWithoutDecoration allows to hide code parts that have a specific decoration
  • lockCodeWithDecoration allows to make read-only code parts within a specific decoration
  • lockCodeWithoutDecoration allows to make read-only code parts outside of a specific decoration
  • updateEditorKeybindingsMode allows to apply vim or emacs keybindings
  • extractRangesFromTokens allows to extract the code sections between a start token and an end token

Installation

npm install @codingame/monaco-editor-wrapper

Usage

Simple usage

You need to call the exposed initialize function, and wait for the returned promise.

You will then be able to interact with the monaco-editor api (by importing monaco-editor) OR the VSCode api (by importing vscode)

Model creation

Instead of using monaco.editor.createModel, it is recommended to use monaco.editor.createModelReference to create models.

It makes it possible for the VSCode service to reference that file by it's reference without breaking (for instance when following file links in source code using LSP).

Optional features

By default, only a minimal set of features is registered (vscode extensions, editor/model services, languages, textmate, dialogs, configuration/keybindings, snippets, accessibility...)

There are some optional features that can be enabled by importing a specific export:

  • @codingame/monaco-editor-wrapper/features/extensionHostWorker enables the worker extension host which allows to run VSCode extensions
  • @codingame/monaco-editor-wrapper/features/notifications enables the VSCode notifications instead of logging into the console
  • @codingame/monaco-editor-wrapper/features/workbench allows to use the full VSCode workbench
  • @codingame/monaco-editor-wrapper/features/typescriptStandalone enables the monaco standalone typescript language feature worker

Those feature can be used if the workbench feature is enabled:

  • @codingame/monaco-editor-wrapper/features/viewPanels enables a few panels (timeline, outline, output, markers, explorer)
  • @codingame/monaco-editor-wrapper/features/search enables the search panel
  • @codingame/monaco-editor-wrapper/features/extensionGallery enables the extension gallery panel and the possibility to install extensions from the marketplace
  • @codingame/monaco-editor-wrapper/features/terminal enables the terminal panel
  • @codingame/monaco-editor-wrapper/features/testing enables the testing panels

Embed language IntelliSense

By default, monaco-editor contains worker to achieve IntelliSense in CSS, SCSS, JavaScript, TypeScript, JSON and HTML.

It's not possible to use them with this lib. However they can be replaced by the corresponding VSCode extension.

To enable them, install and import for following packages:

  • JSON: import '@codingame/monaco-vscode-json-language-features-default-extension'
  • JavaScript/TypeScript: import '@codingame/monaco-vscode-typescript-language-features-default-extension'
  • CSS/SCSS: import '@codingame/monaco-vscode-css-language-features-default-extension'
  • HTML: import '@codingame/monaco-vscode-html-language-features-default-extension'

You also need to import @codingame/monaco-editor-wrapper/features/extensionHostWorker to allows the VSCode extensions to run in a webworker.

Additional apis

User configuration

This library exposed some functions to manage the user global configuration:

  • registerDefaultConfigurations Allows registering default values for some configuration keys which can be overridden
  • updateUserConfiguration Update the user configuration, overrides the default configuration, uses the same syntax as VS Code configuration
  • getUserConfiguration Get back the current user configuration
  • onUserConfigurationChange Get notified when the user configuration change (either after calling updateUserConfiguration or from internal configuration update)
  • getConfiguration Allows to get a given configuration key in a given language
  • onConfigurationChanged Listen to configuration change
  • updateKeybindings aAlows to update the editor keybindings with the same syntax as in VS Code
  • updateEditorKeybindingsMode Switch between vim, emacs or classic keybindings

版本与发布记录

@codingame/monaco-editor-wrapper 共发布 197 个版本,首次发布于 2021/11/10;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
36.0.0latest2026/11/063 天前
35.0.02026/10/2021 天前
34.0.22026/10/011 个月前
34.0.12026/09/301 个月前
34.0.02026/09/301 个月前
33.0.02026/09/221 个月前

其他发布通道:next → 5.4.0-full-workbench.1。

关于 @codingame/monaco-editor-wrapper 的常见问题

@codingame/monaco-editor-wrapper 是什么?

Configured monaco-vscode-api with tools and extensions

如何安装 @codingame/monaco-editor-wrapper?

在项目目录运行 npm install @codingame/monaco-editor-wrapper,或使用 pnpm add / yarn add / bun add。

@codingame/monaco-editor-wrapper 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codingame/monaco-editor-wrapper 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codingame/monaco-editor-wrapper 可以商用吗?

@codingame/monaco-editor-wrapper 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@codingame/monaco-editor-wrapper 的下载量有多少?

根据 npm 官方下载统计,@codingame/monaco-editor-wrapper 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,923 次,日均约 164 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codingame/monaco-editor-wrapper 还在维护吗?

最新版本 36.0.0 发布于 2026/11/06(3 天前);至今共发布 197 个版本,其中过去 12 个月发布了 25 个;首次发布于 2021/11/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。