monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Exclude built-in languages from loading

Open sbuchok opened this issue 7 years ago • 10 comments

monaco-editor version: 0.15.5 Browser: Any OS: Any

I have created a custom language with auto complete provider and syntax highlighting. Works great. I noticed however that all the languages in the basic-languages folder are all getting loaded. This adds extra overhead to our load time (we don't need any of them). Is there a way to exclude them from being loaded at all?

It looks like they are getting loaded at the bottom of main.editor.js and I don't see anything that would allow me to exclude them from getting loaded. Hoping someone else will know.

Thanks

sbuchok avatar Mar 11 '19 17:03 sbuchok

I thought they're loaded lazily and the actual loading shouldn't happen until you have a model with a language id equal to those built-in ones. So as long as your editor's language is not one of them you should be safe.

vasiltabakov avatar Mar 12 '19 06:03 vasiltabakov

You could also try to use the monaco-editor-core npm module, it's also maintained my MS and does not contain the built-in languages & language servers.

mofux avatar Mar 12 '19 11:03 mofux

@vasiltabakov I looked at the demo here: https://microsoft.github.io/monaco-editor/ and sure enough, all the languages aren't loading. For some reason, all the ones in the basic-languages folder for me are. I'm not sure what the difference is ... yet

@mofux does monaco-editor-core allow colorization, custom language, auto completion, suggestion... everything I would need for my own custom language?

sbuchok avatar Mar 12 '19 11:03 sbuchok

I'm on 0.16.0 and requiring editor.main loads this bunch of contribution from basic-languages. I'm not sure if that's related. image

Note: these files doesn't even exist. The files get loaded because they get a html response, but it's not close to being those files >.<

EDIT: Fixed this. Caused because I was importing twice the editor and one was the dev version. My bad.

betoissues avatar Mar 14 '19 20:03 betoissues

well, I am running into this issue as well, is there any documentation on how to explicitly exclude loading language contributions you don't need?

armand1m avatar Nov 12 '19 13:11 armand1m

in the website is not a really good example to follow because they load it using AMD, hence why it loads only what is needed.

the issue I have and most people here as well is because we're using webpack import's and bundling them, so probably basic-languages is not tree-shakable and also not lazy loaded in webpack bundles.

please correct me if I'm wrong, just exploring so far

armand1m avatar Nov 12 '19 13:11 armand1m

@armand1m for me, that is correct. We are bundling ours. Still an issue for us, but since it is an intranet app, less of an issue, but it would be nice to have less stuff loading that really isn't needed.

sbuchok avatar Nov 12 '19 13:11 sbuchok

I'm giving a try on https://github.com/microsoft/monaco-editor-webpack-plugin, as you can set the languages to get bundled as a parameter of the plugin constructor, maybe will help you as well =)

armand1m avatar Nov 12 '19 13:11 armand1m

@armand1m It won't for me, but hopefully it will help someone else. Thanks

sbuchok avatar Nov 12 '19 14:11 sbuchok

The *.contribution files are super tiny and they simply define the fact that a language exists. They are fine to be loaded all the time, and the expectation is that they get bundled in your application, either via webpack, rollup, or by you using the /min AMD bundled version.

Once a model with a certain language is loaded, these tiny definitions are consulted and if a language is found, then the real language coloring / configuration / web worker are loaded.

alexdima avatar Dec 12 '19 09:12 alexdima