Merge pull request #144 from domsew/fixExample

fix monaco-editor-webpack-plugin
This commit is contained in:
Remco Haszing 2021-11-24 18:40:50 +01:00 committed by GitHub
commit d35b72e1fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 18 deletions

View file

@ -1,10 +1,11 @@
# Monaco Editor Webpack Loader Plugin Example
This demo demonstrates how bundle `monaco-editor` and `monaco-yaml` with
[monaco-editor-webpack-plugin](https://github.com/microsoft/monaco-editor-webpack-plugin). The build
output is [esm library](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules).
Example is based on
[link](https://github.com/microsoft/monaco-editor-samples/tree/main/browser-esm-webpack-monaco-plugin).
[monaco-editor-webpack-plugin](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin).
The build output is
[esm library](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). Example is
based on
[link](https://github.com/microsoft/monaco-editor/tree/main/samples/browser-esm-webpack-monaco-plugin).
To start it, simply run:
## Prerequisites

View file

@ -1,5 +1,4 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
export { editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
export { setDiagnosticsOptions } from 'monaco-yaml';
export default monaco;

View file

@ -4,8 +4,29 @@ boolean: true
`;
async function create() {
const monaco = await import('./main.js');
// Dynamic import is possible
const { default: monaco } = await import('./main.js');
// Define schema first
monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({
schemas: [
{
fileMatch: ['*'],
uri: 'my-schema.json',
schema: {
type: 'object',
properties: {
number: {
description: 'number property',
type: 'number',
},
},
},
},
],
});
// Create editor
monaco.editor.create(document.querySelector('.editor'), {
language: 'yaml',
tabSize: 2,

View file

@ -14,12 +14,6 @@ export default {
outputModule: true,
},
devtool: 'source-map',
resolve: {
fallback: {
// Yaml-ast-parser-custom-tags imports buffer. This can be omitted safely.
buffer: false,
},
},
module: {
rules: [
{
@ -38,13 +32,10 @@ export default {
customLanguages: [
{
label: 'yaml',
entry: [
'monaco-yaml/lib/esm/monaco.contribution',
'vs/basic-languages/yaml/yaml.contribution',
],
entry: ['monaco-yaml', 'vs/basic-languages/yaml/yaml.contribution'],
worker: {
id: 'monaco-yaml/lib/esm/yamlWorker',
entry: 'monaco-yaml/lib/esm/yaml.worker',
id: 'monaco-yaml/yamlWorker',
entry: 'monaco-yaml/yaml.worker',
},
},
],