Any import from 'monaco-editor' adds ALL to JS bundle #3719
Replies: 10 comments 1 reply
-
If i import only Interface from 'monaco-editor' namespace in typescript, it should add 0B of javascript. You can use |
Beta Was this translation helpful? Give feedback.
-
@hediet
|
Beta Was this translation helpful? Give feedback.
-
Examples:
You cannot just and importing i haven't found any other way how to import / use these things without bundling 4Mb to main bundle.. (import { CompletionItemInsertTextRule } from 'monaco-editor/esm/vs/language/typescript/lib';,...) |
Beta Was this translation helpful? Give feedback.
-
You can import only types and get the ones you mentioned like this: // you can do this (you could still call it monaco I just renamed it to differentiate):
import type * as monacobase from 'monaco-editor'
// or import the declaration file directly:
import type monaco from 'monaco-editor/esm/vs/editor/editor.api'
type x = monaco.languages.CompletionItemKind.Snippet
type y = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
type xbase = monacobase.languages.CompletionItemKind.Snippet
type ybase = monacobase.languages.CompletionItemInsertTextRule.InsertAsSnippet Ctrl + Click on the import path in VS Code shows you that both import Hope this helps :-) |
Beta Was this translation helpful? Give feedback.
-
Will try, thank you ;) |
Beta Was this translation helpful? Give feedback.
-
what about importing "utility classes" like Range? It will still pack entire monaco :-/ |
Beta Was this translation helpful? Give feedback.
-
You can generally shrink down you bundle size by not importing Let's look at how you can find that file. If you don't use vscode you can always just do this in the Here you can do this in vscode by:
import Range from 'monaco-editor'
.
.
.
import { YYYYYYYY } from './path/to//file.js';
.
.
.
const XXXXXXX = YYYYYYYY();
.
.
.
export const Range = XXXXXXX.Range;
.
.
.
import { Range } from '../path/to/file_where_range_is_implemented.js';
import { Range } from 'monaco-editor/something/somethingelse/path/to/file_where_range_is_implemented.js'; You are probably developing something that is gonna interact with |
Beta Was this translation helpful? Give feedback.
-
Well.. maybe that is the way how to do that, but it is non-standard way - developer should not be forced to do "deep importing" or to do "research". how to import every thing he needs... it should be exported correctly and it should by ESM module, it should avoid reexports, have sideEffects: false set during ESM build etc to be modern, treeshakeable and code-splittable library. If i import
etc, it will NOT bundle entire RXJS to the application and i dont have to import it like So... If we are talking about possible workarounds, there may be a "solution" and i can "deeply import" and it may (have to try first) solve the issue,.. but it is still workaround, right? There should be a way how to import it like this:
and in that case - only Range class should be bundled to final chunk, or... to make it better for code splitting - there should be more entry points:
I am just asking for modern solution, which have other libraries in common. |
Beta Was this translation helpful? Give feedback.
-
I'm also seeing this issue. Bundle sizes are huge. |
Beta Was this translation helpful? Give feedback.
-
Nope, we have gone the way to lazy load components using Monaco.... I have already lost all of hope it will be done correctly from Monaco side.... |
Beta Was this translation helpful? Give feedback.
-
Reproducible in vscode.dev or in VS Code Desktop?
Reproducible in the monaco editor playground?
Monaco Editor Playground Code
No response
Reproduction Steps
Installed version:
"monaco-editor": "^0.21.3",
Any import from 'monaco-editor' leads to add everything to generated JS bundle, even in prod build.
like:
or:
or:
import * as monaco from 'monaco-editor';
And entire monaco editor will be added to final PRODUCTION bundle
Actual (Problematic) Behavior
If i import ANYTHING from 'monaco-editor' namespace in typescript, it will add entire 4MB chunk of JS to production bundle.
There is not any way how to use - for the instance, only Interfaces (types) or enums from 'monaco-editor' namespace in typescript without adding the entire editor to final bundle.
It is not treeshakeabl
Expected Behavior
If i import only Interface from 'monaco-editor' namespace in typescript, it should add 0B of javascript.
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions