Skip to content

fix: split validators.ts into multiple files to allow proper tree shaking #519

@gempain

Description

@gempain

In validators.ts, line 20-22:

private libPhoneNumber = {
    phoneUtil: require("google-libphonenumber").PhoneNumberUtil.getInstance(),
};

When class-validator is bundled with webpack, google-libphonenumber, which represents 71% of the bundle size, is embedded, even if you don't use the phone number validator. See this bundle analysis made with webpack-bundle-analyzer:

Screenshot 2020-02-08 at 17 43 41

Validators should be split into different files, allowing to import only the needed files without extra code and thus enabling proper tree shaking when bundling dependencies with webpack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: done/releasedIssue has been completed, no further action is needed.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions