0.5.19 • Published 3 years ago

@uifabric/monaco-editor v0.5.19

Weekly downloads
381
License
MIT
Repository
github
Last release
3 years ago

@uifabric/monaco-editor

Version of monaco-editor with the CSS files transformed to JS which can be loaded onto the page using @microsoft/load-themed-styles, plus some Webpack configuration helpers.

Package contents

  • esm/*: Copy of monaco-editor/esm/* but with the CSS files transformed. (This package doesn't include the AMD variant since it has a built-in CSS loader.)
  • monaco-typescript.d.ts: Proper typings for various things used/returned by monaco.typescript, including TypeScriptWorker (generated by merging monaco-typescript/release/esm/*.d.ts)
  • scripts/addMonacoWebpackConfig.js: Add Monaco-related webpack configuration
  • lib/configureEnvironment.js: Set up MonacoEnvironment runtime config

How to use with Webpack

1. Webpack configuration

In your webpack.config.js, call the addMonacoWebpackConfig helper to add Monaco-related configuration (note that it returns a new configuration object):

const { addMonacoWebpackConfig } = require('@uifabric/monaco-editor/scripts/addMonacoWebpackConfig');

// Somewhere in this file, call:
config = addMonacoWebpackConfig(originalConfig, includeAllLanguages);

Parameters:

  • config (webpack.Configuration): Your configuration object. Its entry must be an object (not an array or function), and the output.globalObject setting (if any) will be ignored.
  • includeAllLanguages (boolean):
    • false (default): Imports for @uifabric/monaco-editor will be remapped to @uifabric/monaco-editor/lib/monacoCoreBundle, which includes only core editor features and TypeScript language features. Entry configs will be added for the main editor worker (editor.worker.js) and TS worker (ts.worker.js) but not other languages.
    • true: Imports for @uifabric/monaco-editor will be remapped to @uifabric/monaco-editor/lib/monacoBundle, which includes all language contributions. Also, entry configs will be added for CSS/HTML/JSON workers in addition to TS.

2. Runtime configuration

This project provides two options for setting up global Monaco configuration at runtime. The options are outlined below, but both involve a config object with the following properties:

  • baseUrl (string): CDN path or other path where built files are served from. (. is typical for local serve builds and other non-CDN scenarios.)
  • useMinified (boolean, optional): Whether to use the .min versions of the files. (Assumes you have an additional "production mode" webpack config which generates .min versions of all entry entries.)
  • crossDomain (boolean, optional): Whether to use a configuration variant which works when this script lives on a different domain than the core Monaco scripts.

Option A: Manual

In a root file for your project, import and call the configuration helper manually:

import { configureEnvironment } from '@uifabric/monaco-editor/lib/configureEnvironment';

configureEnvironment(config);

This lightweight helper sets up the global MonacoEnvironment required for Monaco to load the worker files generated by the webpack config (it doesn't import any actual Monaco files). Its config parameter is the simple configuration object described above.

Option B: Automatic using global

Somewhere in a root file for your project (the Fluent UI React projects do this in index.html), define a global variable MonacoConfig with the properties described above. Basic example:

window.MonacoConfig = {
  baseUrl: '.',
  useMinified: false,
};

Then the first time you import @uifabric/monaco-editor, it will automatically call configureEnvironment with the global object.

(This works because the Webpack config remaps @uifabric/monaco-editor imports to point to either lib/monacoBundle or lib/monacoCoreBundle, both of which re-export Monaco things and call configureEnvironment as a side effect.)

3. Using the editor

When you're ready to use the editor, import as follows:

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

See the Monaco documentation for further usage instructions.

If you need types from monaco-typescript, import as follows:

import { TypeScriptWorker } from '@uifabric/monaco-editor/monaco-typescript.d';

Note that you may run into conflicts with these types if you're on a different TypeScript version than the one the typings were generated against.

0.5.19

3 years ago

0.5.18

4 years ago

0.5.17

4 years ago

0.5.16

4 years ago

0.5.15

4 years ago

0.5.14

4 years ago

0.5.13

4 years ago

0.5.12

4 years ago

0.5.11

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.4

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago