0.0.7 • Published 6 years ago

@timkendrick/monaco-editor-loader v0.0.7

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

@timkendrick/monaco-editor-loader

npm version Stability

Webpack loader for the Monaco editor

Installation

npm install @timkendrick/monaco-editor-loader --save-dev

Usage

This loader allows you to create a Monaco editor build with arbitrary extensions enabled, as well as optionally bundling web worker scripts into the main output.

See the @timkendrick/monaco-editor repository for a real-life example.

Scenario 1: Serving worker scripts separately (requires external server):

{
  loader: '@timkendrick/monaco-editor-loader',
  options: {
    modules: [
      {
        name: 'vs',
        root: 'path/to/vscode/src',
      },
      {
        name: 'vs/extension/name',
        root: 'path/to/extension/src',
        main: 'monaco.contribution',
        include: true,
      },
      {
        name: 'vs/library/name',
        root: 'path/to/library/src',
        main: 'monaco.contribution',
      },
    ],
    workers: [
      {
        name: 'workerMain.js',
        main: 'path/to/worker/main.ts',
        includes: [
          'path/to/first/worker/service.ts',
          'path/to/second/worker/service.ts',
        ],
      },
    ],
  },
}

In the above example, the compilation emits additional worker scripts that are loaded at runtime from the webpack publicPath directory.

This directory can be overridden at runtime by specifying the MonacoEnvironment.baseUrl global variable before the bundle script is loaded:

<script>
  window.MonacoEnvironment = {
    baseUrl: 'path/to/worker/scripts'
  };
</script>
<script src="monaco/index.js"></script>

Scenario 2: Bundling worker scripts into main output file (no additional server required):

{
  loader: '@timkendrick/monaco-editor-loader',
  options: {
    workerOptions: {
      inline: true,
    },
    modules: [
      {
        name: 'vs',
        root: 'path/to/vscode/src',
      },
      {
        name: 'vs/extension/name',
        root: 'path/to/extension/src',
        main: 'monaco.contribution',
        include: true,
      },
      {
        name: 'vs/library/name',
        root: 'path/to/library/src',
        main: 'monaco.contribution',
      },
    ],
    workers: [
      {
        name: 'workerMain.js',
        main: 'path/to/worker/main.ts',
        includes: [
          'path/to/first/worker/service.ts',
          'path/to/second/worker/service.ts',
        ],
      },
    ],
  },
}

In the above example, worker scripts will be embedded within the main output bundle.

Loader options

NameTypeRequiredDefaultDescription
modulesArray<ModuleDefinition>No[]Paths to Monaco AMD module definition files
workersArray<WorkerDefinition>No[]Worker modules to be included in the compiled output
workerOptionsobjectNo{}Configuration options for worker scripts
workerOptions.inlinebooleanNofalseWhether to bundle worker scripts into the main bundle
workerOptions.filenamestringNo"[hash].worker.js"Filename template for worker scripts
workerOptions.baseUrlstringNowebpack publicPathBase URL from which to load worker scripts at runtime

ModuleDefinition

NameTypeRequiredDefaultDescription
namestringYesN/AVisual Studio extension name
rootstringYesN/APath to extension source files
mainstringNoundefinedPath to extension entry point file, relative to root
includebooleanNofalseWhether to include extension entry point in output bundle

WorkerDefinition

NameTypeRequiredDefaultDescription
namestringYesN/AName of worker output script
mainstringYesN/APath to worker entry point file
includesArray<string>No[]List of additional service entry point files to bundle into worker script
0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago