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

Remove unused classes #782

Closed
flunderpero opened this issue Feb 10, 2021 · 4 comments
Closed

Remove unused classes #782

flunderpero opened this issue Feb 10, 2021 · 4 comments

Comments

@flunderpero
Copy link

flunderpero commented Feb 10, 2021

We use custom generator code to generate Typescript classes from a Protobuf definition. We keep all classes in a single, rather big module. A class looks roughly like this:

class MyEntity {
    // Some static constants
    static string HTTP_METHOD = "GET"

    // Properties
    public name: string

    // Static entry point for deserialization
    static _from_pb() { ... }

    to_pb() { ... }
}

When bundling the code for the web-app, all classes are preserved in the output whether they are used or not.

We build like this:

await esbuild(
{
        entryPoints: ["index.ts"],
        outdir: "out",
        format: "esm",
        tsconfig: "./tsconfig.json"),
        sourcemap: "external",
        minifyIdentifiers: false,
        minifySyntax: true,
        minifyWhitespace: true,
        bundle: true,
        keepNames: true,
        target: "es2017",
})

Edit: I just checked: Some classes are removed from the output, but I cannot see any pattern.

@flunderpero
Copy link
Author

If I remove the static "constants" (HTTP_METHOD) then the unused classes are removed from output.

@flunderpero
Copy link
Author

I tried to generate the Typescript code like this static HTTP_METHOD = <const>"GET" but it did not change anything. I know that esbuild only works on JS and ignores Typescript's syntax.

Is there a chance to make this work?

@flunderpero
Copy link
Author

But even after I "fix" the static constants there are still unused classes in the resulting bundle.

@evanw
Copy link
Owner

evanw commented Feb 10, 2021

I believe this is a duplicate of #175. Closing as a duplicate.

@evanw evanw closed this as completed Feb 10, 2021
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

2 participants