Document the Webpack Monaco Editor Loader Plugin

This commit is contained in:
Alex Dima 2018-04-12 09:24:52 +02:00
parent b5607fec63
commit 139273dc0a

View file

@ -6,6 +6,53 @@ Here is the most basic script that imports the editor using ESM with webpack.
More self-contained samples are available at [monaco-editor-samples](https://github.com/Microsoft/monaco-editor-samples). More self-contained samples are available at [monaco-editor-samples](https://github.com/Microsoft/monaco-editor-samples).
---
### Option 1: Using the Monaco Editor Loader Plugin
This is the easiest method, and it allows for options to be passed in to the plugin in order to select only a subset of editor features or editor languages. Read more about the [Monaco Editor Loader Plugin](https://github.com/Microsoft/monaco-editor-webpack-plugin), which is a community authored plugin.
* `index.js`
```js
import * as monaco from 'monaco-editor';
monaco.editor.create(document.getElementById('container'), {
value: [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n'),
language: 'javascript'
});
```
* `webpack.config.js`
```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']
}]
},
plugins: [
new MonacoWebpackPlugin()
]
};
```
---
### Option 2: Using plain webpack
* `index.js` * `index.js`
```js ```js
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
@ -74,5 +121,4 @@ module.exports = {
) )
] ]
}; };
``` ```