mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Document the Webpack Monaco Editor Loader Plugin
This commit is contained in:
parent
b5607fec63
commit
139273dc0a
1 changed files with 93 additions and 47 deletions
|
|
@ -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';
|
||||||
|
|
@ -63,7 +110,7 @@ module.exports = {
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
use: [ 'style-loader', 'css-loader' ]
|
use: ['style-loader', 'css-loader']
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
@ -74,5 +121,4 @@ module.exports = {
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue