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

refactor: update build process to enable tree shaking #568

Merged
merged 11 commits into from
Apr 17, 2020
Merged

refactor: update build process to enable tree shaking #568

merged 11 commits into from
Apr 17, 2020

Conversation

vlapo
Copy link
Contributor

@vlapo vlapo commented Mar 30, 2020

Hi folks,

long-awaited refactor is here. As PR #258 is pretty old I moved main @HonoluluHenk idea to this PR and improved build process.

What is done:

  • each validator/decorator moved to separate file
  • imports stay unchanged (main difference between this PR and Smaller bundle size #258) - import { IsString } from 'class-validator';
  • build process using rollup - enable tree shaking

Breaking changes:

  • breaking changes from [email protected] - will mentione in changelog later
  • all validations (except system ones) are type ValidationTypes.CUSTOM_VALIDATION now - mostly internal change
  • all validators from Validator class was removed - because of tree shaking. So you have to use:
import {isString} from "class-validator";
isString(1); // false

instead of:

import {Validator} from "class-validator";
// Validation methods
const validator = new Validator();
validator.isString(1); // false

TODO:

  • try use validator lib tree shakeable feature and push bundle size down event more
  • test with nestjs
  • test, review and clean code
  • update README.md and CHANGELOG.md

Testing:
This PR is published under class-validator@tree-shaking tag. I would like to ask everyone for help in testing and reviewing PR. I tested it on simple boilerplate angular 8 application and results are:

  • Without @IsPhoneNumber validator used:
    • main-es5 bundle size before 891kB <-> after 256kB
    • main-es2015 bundle size before 859kB <-> after 221kB
  • With @IsPhoneNumber:
    • main-es5 bundle size before 891kB <-> after 790kB
    • main-es2015 bundle size before 859kB <-> after 755kB

Close #258
Close #248
Close #247
Close #212

@vlapo vlapo mentioned this pull request Mar 30, 2020
@vlapo
Copy link
Contributor Author

vlapo commented Apr 3, 2020

[email protected] published. I updated rollup config a little bit and add .min.js bundle files.
@patrykkrawczyk thnx for pointing me to agadoo tool.

@vlapo vlapo changed the title refactor: move validation functions/decorators into separate files and update build process to enable tree shaking refactor: update build process to enable tree shaking Apr 17, 2020
@vlapo vlapo merged commit 11a7b8b into typestack:master Apr 17, 2020
@vlapo vlapo deleted the refactor-smaller-bundle branch April 17, 2020 21:22
@vlapo vlapo restored the refactor-smaller-bundle branch April 17, 2020 21:24
@github-actions
Copy link

github-actions bot commented Aug 3, 2020

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
1 participant