Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate tree-shakeable Typescript code #355

Open
Atulin opened this issue Dec 21, 2024 · 0 comments
Open

Generate tree-shakeable Typescript code #355

Atulin opened this issue Dec 21, 2024 · 0 comments

Comments

@Atulin
Copy link

Atulin commented Dec 21, 2024

Quick refresher on tree-shaking:

export const foo = () => ...
export const bar = () => ...

when referenced with

import { foo } from 'blah';

foo();

will generate

const foo = () => ...
foo();

while

export class Blah {
    function foo() { ... }
    function bar() { ... }
}

when referenced with

import { Blah } from 'blah';

Blah.foo();

will generate

class Blah {
    function foo() { ... }
    function bar() { ... }
}
Blah.foo();

Currently, MemoryPack generates the latter. Meaning, if I only need the serialize() function, the entire class gets bundled anyway. Lots of code that I have no use for.

Additionally, classes get bundled pretty much as-is, while interfaces could be stripped away at bundle time.

For maximum tree-shaking compatibility and minimum bundle sizes, MemoryPack should be generating interfaces and loose functions, for example

export interface Person {
    name: string;
    surname: string;
    shoeSize: number;
    birthday: Date;
}

export function serialize(value: Person | null): Uint8Array {
    // snip...
}

export function deserialize(buffer: ArrayBuffer): Person | null {
    // snip...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant