alina sireneva
690948b8b1
All checks were successful
Build and deploy typedoc / build (push) Successful in 5m15s
Co-authored-by: Kamilla 'ova <me@kamillaova.dev> Co-authored-by: Alina Chebakova <chebakov05@gmail.com> Co-authored-by: Kravets <57632712+kravetsone@users.noreply.github.com> Co-authored-by: starkow <hello@starkow.dev> Co-authored-by: sireneva <150665887+sireneva@users.noreply.github.com>
34 lines
No EOL
994 B
Markdown
34 lines
No EOL
994 B
Markdown
# Tree-shaking
|
|
|
|
Being a ESM-first library, mtcute supports tree-shaking out of the box.
|
|
|
|
This means that you can import only the parts of the library that you need,
|
|
and the bundler will remove all the unused code.
|
|
|
|
## Usage
|
|
|
|
To start using tree-shaking, there are a few things to keep in mind:
|
|
- Do not use `TelegramClient`. Use `BaseTelegramClient` instead, and import the needed methods.
|
|
|
|
For example, instead of this:
|
|
```ts
|
|
import { TelegramClient } from '@mtcute/web'
|
|
|
|
const tg = new TelegramClient({ ... })
|
|
|
|
await tg.sendText(...)
|
|
```
|
|
|
|
you should use this:
|
|
|
|
```ts
|
|
import { BaseTelegramClient } from '@mtcute/web'
|
|
import { sendText } from '@mtcute/web/methods.js'
|
|
|
|
const tg = new BaseTelegramClient({ ... })
|
|
|
|
await sendText(tg, ...)
|
|
```
|
|
|
|
- TL serialization is currently not tree-shakeable, because it is done via a global map of constructors.
|
|
There's no ETA on when (or whether at all) this will be changed, so there *will* be ~300 KB of non-shakeable code. |