TypeFox / monaco-languageclient

Repo hosts npm packages for monaco-languageclient, vscode-ws-jsonrpc, monaco-editor-wrapper, @typefox/monaco-editor-react and monaco-languageclient-examples
https://www.npmjs.com/package/monaco-languageclient
MIT License
992 stars 169 forks source link

Large bundle size #678

Open Lemour-sudo opened 2 weeks ago

Lemour-sudo commented 2 weeks ago

I am trying to use the MonacoEditorReactComp along with the language client in an existing project.

The problem is that the addition of this library significantly increases the final bundle size by about 7mb without compression. This creates a problem for us when deploying our application as the deployment platform enforces a small uncompressed bundle size limit of about 2mb.

Is there a way to reduce the final bundle size? I was thinking if it could also be possible to only run the MonacoEditorReactComp in the existing project such that the final bundle size will be lower, then have the language client running in a separate repo and connect it to the MonacoEditorReactComp through a web socket connection. I also tried using another monaco react library, https://www.npmjs.com/package/@monaco-editor/react, and it seems to have result in a small bundle size with just a few hundred kbs. But I could not link it to the monaco language client.

CGNonofr commented 2 weeks ago

The problem is, if you want to use the language client, you need the VScode api, which needs all the mainThread/extHost stuff which are kind of heavy

The other issue is that monaco-language have ALL service overrides as dependency, and just import it or not depending on the configuration. most of them won't be loaded by the client but it's still present in the bundle @kaisalmen

kaisalmen commented 2 weeks ago

The other issue is that monaco-language have ALL service overrides as dependency

That is not true. It only imports this:

└─┬ monaco-languageclient@8.5.0 -> .\packages\client
     ├── @codingame/monaco-vscode-extensions-service-override@5.2.0
     ├── @codingame/monaco-vscode-languages-service-override@5.2.0
     ├── @codingame/monaco-vscode-localization-service-override@5.2.0
     ├── @codingame/monaco-vscode-model-service-override@5.2.0
     ├── monaco-editor@npm:@codingame/monaco-vscode-editor-api@5.2.0
     ├── vscode-languageclient@9.0.1
     └── vscode@npm:@codingame/monaco-vscode-api@5.2.0
CGNonofr commented 2 weeks ago

What about the wrapper package?

kaisalmen commented 2 weeks ago

@CGNonofr bundle sizes came down already by the measures you took on the monaco-vscode-api side, but we can't below the dependencies stated above. Using the languageclient or monaco-editor-wrapper comes with a price, but it is pretty small in comparison to a real vscode (vscode.dev takes 46 MB).

kaisalmen commented 2 weeks ago

What about the wrapper package?

It also only adds what is needed.

CGNonofr commented 2 weeks ago

There are a few more services override though, like the textmate service override, which uses a 450ko wasm

@Lemour-sudo do you have a bundler report? you can use https://www.npmjs.com/package/webpack-bundle-analyzer for webpack or https://www.npmjs.com/package/vite-bundle-visualizer for vite

kaisalmen commented 2 weeks ago

Also, build:production of the angular verification example should provide you with useful data on the final bundle size. It makes use of the wrapper. The react component only adds react.

Lemour-sudo commented 2 weeks ago
vite-visualizer

The image I have attached shows the bundles that are used when just importing the react component and logging it (this is to isolately check what the react component uses independent of the client).