You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
6.2 KiB
Markdown
108 lines
6.2 KiB
Markdown
7 years ago
|
# Monaco Editor Webpack Loader Plugin
|
||
7 years ago
|
|
||
7 years ago
|
A plugin to simplify loading the [Monaco Editor](https://github.com/Microsoft/monaco-editor) with [webpack](https://webpack.js.org/).
|
||
7 years ago
|
|
||
|
## Installing
|
||
3 years ago
|
|
||
7 years ago
|
```sh
|
||
|
npm install monaco-editor-webpack-plugin
|
||
|
```
|
||
|
|
||
|
## Using
|
||
3 years ago
|
|
||
|
- `webpack.config.js`:
|
||
|
|
||
7 years ago
|
```js
|
||
|
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
||
5 years ago
|
const path = require('path');
|
||
7 years ago
|
|
||
|
module.exports = {
|
||
3 years ago
|
entry: './index.js',
|
||
|
output: {
|
||
|
path: path.resolve(__dirname, 'dist'),
|
||
|
filename: 'app.js'
|
||
|
},
|
||
|
module: {
|
||
|
rules: [
|
||
|
{
|
||
|
test: /\.css$/,
|
||
|
use: ['style-loader', 'css-loader']
|
||
|
},
|
||
|
{
|
||
|
test: /\.ttf$/,
|
||
|
use: ['file-loader']
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
plugins: [new MonacoWebpackPlugin()]
|
||
7 years ago
|
};
|
||
|
```
|
||
|
|
||
3 years ago
|
- `index.js`:
|
||
|
|
||
7 years ago
|
```js
|
||
3 years ago
|
import * as monaco from 'monaco-editor';
|
||
7 years ago
|
// or import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||
|
// if shipping only a subset of the features & languages is desired
|
||
7 years ago
|
|
||
|
monaco.editor.create(document.getElementById('container'), {
|
||
3 years ago
|
value: 'console.log("Hello, world")',
|
||
|
language: 'javascript'
|
||
7 years ago
|
});
|
||
|
```
|
||
|
|
||
|
## 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:
|
||
|
|
||
3 years ago
|
- `filename` (`string`) - custom filename template for worker scripts, respects the same options as [loader-utils' interpolateName](https://github.com/webpack/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.
|
||
5 years ago
|
|
||
3 years ago
|
- default value: <!-- LANGUAGES_BEGIN -->`['abap', 'apex', 'azcli', 'bat', 'bicep', 'cameligo', 'clojure', 'coffee', 'cpp', 'csharp', 'csp', 'css', 'dart', 'dockerfile', 'ecl', 'elixir', 'flow9', 'fsharp', 'go', 'graphql', 'handlebars', 'hcl', 'html', 'ini', 'java', 'javascript', 'json', 'julia', 'kotlin', 'less', 'lexon', 'liquid', 'lua', 'm3', 'markdown', 'mips', 'msdax', 'mysql', 'objective-c', 'pascal', 'pascaligo', 'perl', 'pgsql', 'php', 'pla', 'postiats', 'powerquery', 'powershell', 'protobuf', 'pug', 'python', 'qsharp', 'r', 'razor', 'redis', 'redshift', 'restructuredtext', 'ruby', 'rust', 'sb', 'scala', 'scheme', 'scss', 'shell', 'solidity', 'sophia', 'sparql', 'sql', 'st', 'swift', 'systemverilog', 'tcl', 'twig', 'typescript', 'vb', 'xml', 'yaml']`<!-- LANGUAGES_END -->.
|
||
6 years ago
|
|
||
3 years ago
|
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:
|
||
6 years ago
|
|
||
3 years ago
|
| Language | Instantiator |
|
||
|
| ---------- | ------------ |
|
||
|
| javascript | typescript |
|
||
|
| handlebars | html |
|
||
|
| scss, less | css |
|
||
6 years ago
|
|
||
3 years ago
|
- `features` (`string[]`) - include only a subset of the editor features.
|
||
6 years ago
|
|
||
3 years ago
|
- default value: <!-- FEATURES_BEGIN -->`['accessibilityHelp', 'anchorSelect', 'bracketMatching', 'caretOperations', 'clipboard', 'codeAction', 'codelens', 'colorPicker', 'comment', 'contextmenu', 'coreCommands', 'cursorUndo', 'dnd', 'documentSymbols', 'find', 'folding', 'fontZoom', 'format', 'gotoError', 'gotoLine', 'gotoSymbol', 'hover', 'iPadShowKeyboard', 'inPlaceReplace', 'indentation', 'inlayHints', 'inlineCompletions', 'inspectTokens', 'linesOperations', 'linkedEditing', 'links', 'multicursor', 'parameterHints', 'quickCommand', 'quickHelp', 'quickOutline', 'referenceSearch', 'rename', 'smartSelect', 'snippets', 'suggest', 'toggleHighContrast', 'toggleTabFocusMode', 'transpose', 'unusualLineTerminators', 'viewportSemanticTokens', 'wordHighlighter', 'wordOperations', 'wordPartOperations']`<!-- FEATURES_END -->.
|
||
|
- excluded features: It is also possible to exclude certain default features prefixing them with an exclamation mark '!'.
|
||
7 years ago
|
|
||
3 years ago
|
- `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](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
|
||
|
- default value: `false`.
|
||
4 years ago
|
|
||
5 years ago
|
## Version Matrix
|
||
|
|
||
3 years ago
|
| `monaco-editor-webpack-plugin` | `monaco-editor` |
|
||
|
| ------------------------------ | -------------------------------------- |
|
||
|
| `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.*` |
|
||
5 years ago
|
|
||
7 years ago
|
## Contributing
|
||
7 years ago
|
|
||
3 years ago
|
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||
7 years ago
|
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](https://opensource.microsoft.com/codeofconduct/).
|
||
|
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||
|
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|