Reputation: 13277
I have ESM version of Monaco set up using the Webpack Loader plugin. I want to add monaco yaml plugin, and I struggle to understand how do I do that. I'm using the Integrating the ESM version of the Monaco Editor guide and Monaco Yam plugin README.
The documentation on yaml plugin says to set up getWorker
function in MonacoEnvironment; however, the ESM documentation says to either use Webpack loader, or to set up
getWorkerUrl` function, so three different ways to set this up in total.
getWorker
and getWorkerUrl
functions hint that they are interchangeable — are they? Who calls these functions?getWorkerUrl
uses ./ts.worker.bundle.js
for typescript, whereas getWorker
uses monaco-editor/esm/vs/language/typescript/ts.worker
url to create typescript worker. These urls seem very similar. Is there 1-to-1 relationship here, and what is it? If there is, where is the monaco-editor/esm/vs/language/typescript
prefix added?getWorker
function source uses monaco-yaml/yaml.worker
url for the plugin. If urls in getWorkerUrl
are automatically added monaco-editor/...
prefixes, how can I use getWorkerUrl
function with this url?IFeatureDefinition
with label
, entry
, worker
of type IWorkerDefinition
, which in turn also has id
and string
. How do all of these properties relate to the getWorkerUrl
parameters of moduleId
and label
(is that the label of a feature or a worker? What's the difference?) and the return value of url?Overall, there's no proper information about exact contracts of all this configuration, just simple examples, and a lot of things that seem to be vaguely similar between all the three methods (getWorker
, getWorkerUrl
and MonacoWebpackPlugin
) without any clarifications, so I just feel very confused by it. These questions are my best attempt at structuring all the information available to me.
Upvotes: 0
Views: 1446
Reputation: 13277
I've added the answer to the plugin's README file:
You can extend the plugin's configuration. Extend your
webpack.config.js
file with the following:
import { MonacoWebpackPlugin } from 'monaco-editor-webpack-plugin';
export default {
// ...the rest of your webpack configuration...
plugins: [
new MonacoWebpackPlugin({
languages: ['yaml'],
customLanguages: [
{
label: 'yaml',
entry: 'monaco-yaml',
worker: {
id: 'monaco-yaml/yamlWorker',
entry: 'monaco-yaml/yaml.worker',
},
},
],
}),
],
};
You can also refer to the example of a complete project.
Upvotes: 1