7.1.0 • Published 9 months ago

monaco-editor-webpack-plugin v7.1.0

Weekly downloads
178,154
License
MIT
Repository
github
Last release
9 months ago

Monaco Editor Webpack Loader Plugin

A plugin to simplify loading the Monaco Editor with webpack.

Installing

npm install monaco-editor-webpack-plugin

Using

  • webpack.config.js:
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require('path');

module.exports = {
	entry: './index.js',
	output: {
		path: path.resolve(__dirname, 'dist'),
		filename: 'app.js'
	},
	module: {
		rules: [
			{
				test: /\.css$/,
				use: ['style-loader', 'css-loader']
			},
			{
				test: /\.ttf$/,
				type: 'asset/resource'
			}
		]
	},
	plugins: [new MonacoWebpackPlugin()]
};

If using Webpack 4 or lower, it is necessary to use the file-loader instead of Asset Modules like the code below:

{
	test: /\.ttf$/,
	use: ['file-loader']
}
  • index.js:
import * as monaco from 'monaco-editor';
// or import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
// if shipping only a subset of the features & languages is desired

monaco.editor.create(document.getElementById('container'), {
	value: 'console.log("Hello, world")',
	language: 'javascript'
});

Options

Options can be passed in to MonacoWebpackPlugin. They can be used to generate a smaller editor bundle by selecting only certain languages or only certain editor features:

  • filename (string) - custom filename template for worker scripts, respects the same options as loader-utils' interpolateName. Useful for adding content-based hashes so that files can be served with long-lived caching headers.
    • default value: '[name].worker.js'.
  • publicPath (string) - custom public path for worker scripts, overrides the public path from which files generated by this plugin will be served. This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-origin when using a CDN for other static resources. Use e.g. '/' if you want to load your resources from the current origin..
    • default value: ''.
  • languages (string[]) - include only a subset of the languages supported. By default, all languages shipped with the monaco-editor will be included.

    Some languages share the same web worker. If one of the following languages is included, you must also include the language responsible for instantiating their shared worker:

    LanguageInstantiator
    javascripttypescript
    handlebarshtml
    scss, lesscss

    To view a list of all available languages, you can run import metadata from 'monaco-editor/esm/metadata'; console.log(metadata.languages);.

  • features (string[]) - include only a subset of the editor features. By default, all features shipped with the monaco-editor will be included. Instead of enumerating included features, it is also possible to exclude certain default features prefixing them with an exclamation mark '!'.

    To view a list of all available features, you can run import metadata from 'monaco-editor/esm/metadata'; console.log(metadata.features);.

  • globalAPI (boolean) - specify whether the editor API should be exposed through a global monaco object or not. This option is applicable to 0.22.0 and newer version of monaco-editor. Since 0.22.0, the ESM version of the monaco editor does no longer define a global monaco object unless global.MonacoEnvironment = { globalAPI: true } is set (change log).

    • default value: false.

Version Matrix

monaco-editor-webpack-pluginmonaco-editor
7.*.*>= 0.31.0
6.*.*0.30.*
5.*.*0.29.*
4.*.*0.25.*, 0.26.*, 0.27.*, 0.28.*
3.*.*0.22.*, 0.23.*, 0.24.*
2.*.*0.21.*
1.9.*0.20.*
1.8.*0.19.*
1.7.*0.18.*

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

@amamiryoin/formui@hotfusion/typerpkpmgispkpmgisanolanpro-spark-screen-buildervue-form-builder-fixedspaceone-consolescimetro-coreics-form-bundle-publish-test@vueux/flowmariadb-maxscale-query-editorlyw-test-bos-geoyn-dashboardweb_relationlg-ly-web-components@infinitebrahmanuniverse/nolb-monadplus-guijswl-lowcode-scenejswl-lowcode-screenjswl-lowcode-system@everything-registry/sub-chunk-2195@mega-apps/lowcodestrapi-plugin-export-datakstone-foundation-ui-corelight-editorhh-visual-dragkingbase-sqleditorkarenloar-kilakarenloar-kila-v2ldt-my-editorlcp-testimjoyipymonacojpaas-common-libjpaas-common-lib-szswjpaas-common-lib-wmjpaas-common-lib2jpaas-common-lib3jpaas-common-lib_update_xiaguobinlog-vue2.x-element-componentsmonster-egluck-code-editormarkdown-editor-demomonaco-editor-vue-testmonaco-editor-commonaco-editor-commonjsmonaco-json-editormonaco-yaml-reactmonaco-vue3-editorheeramisjylibnaza-component-tool@mega-apps/ami-lowcodencform-makernemo125467413next-monaco-editorlx_web_designlx_web_design_devmin-editormid-editor-jslowcode-clinteract-on-jupyterm-react-scriptsmcdis-webcontrolcenter-interfacemcdis-webcontrolcenter-interface-2edit-page2022dynamic-characteristicgksk-base-sulagatsby-theme-zhgatsby-theme-nestxgumjshaier-uihanzhi-uihanta-monaco-editorforms_kdgatsby-theme-iotgg-vue-monaco-editorgiv-scriptsexplorer-testfluent-rn-websiteg6-v1fonto-react-scriptsflame-settingnowjs-react-material-uioli-js-playground@zalastax/nolb-mona@wibetter/amis-widget-cli@toriyama/opencvjs-playground@xins/devtool@ykd/gum@transformer-cli/editor@tommy2gis/geo-editorpw-jstool@testbrhm/vuejsdemopkpmgisbplat_tears@thiagoelg/kaoto-ui@21epub/epub-json-panelamis-widget-cli@akphi/dev-utils
7.1.0

9 months ago

7.0.0

2 years ago

7.0.1

2 years ago

6.0.0

2 years ago

5.0.0

2 years ago

4.2.0

3 years ago

4.1.2

3 years ago

4.1.0

3 years ago

4.1.1

3 years ago

4.0.0

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.0

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.4

6 years ago

1.5.3

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago