-
Notifications
You must be signed in to change notification settings - Fork 809
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
Smaller bundle size #258
Smaller bundle size #258
Conversation
@@ -2864,7 +2863,7 @@ describe("isPhoneNumber", function() { | |||
someProperty: string; | |||
} | |||
|
|||
it("should not fail if validator.validate said that its valid", function(done) { | |||
it.only("should not fail if validator.validate said that its valid", function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you remove only
?
@HonoluluHenk Are you still alive? :D |
Sorry, currently on holidays |
Since this introduces an API change (changed import) and requires lots of tedious work for me to implement this for all validator functions/annotations, I'd like to have the opinion of the package maintainer... Care to comment, @NoNameProvided? |
2712625
to
108f560
Compare
Hi @HonoluluHenk! Yes, this is great work! I will help with the changes as my time allows. I have been inactive for a while now, but now I managed to spend time on OSS again (last week I have caught up with the changes in |
@NoNameProvided My pr would be easy to check out too :) |
@HonoluluHenk Can you fix conflicts? |
5cc9b4d
to
1320d29
Compare
@NoNameProvided did some more migrations, but found a bug: |
@NoNameProvided: migration done. |
Measures with a minimal angular application: Using class-validator 0.9.1: bundle total 864k Compare to this refactoring: |
Wow I really like this. How do you measure bundle size btw? |
@maxime1992 in angular cli one can not change webpack config? In vue cli we can do it easily |
You could eject or use ngx-build-plus for ex but it's definitely not worth it in this case as I do not use the library at all and a fix is coming. So I decided to go for the ugly quick fix there :) |
To get rid of libphonenumber for the angular-cli I came up with a hack. The idea is a combination of the comments from maxime1992 and Djaler In your workspace save this module.exports = {
PhoneNumberUtil: {
getInstance() {
return null;
},
},
}; in {
"scripts": {
"postinstall": "npx nodecat libphonenumber-stub.js > ./node_modules/google-libphonenumber/dist/libphonenumber.js || true"
}
} hint: we use |
@NoNameProvided any chance this PR would be merged in ? |
please merge this @vlapo @NoNameProvided @quentinus95 |
@HonoluluHenk would you be able to rebase your changes on the latest target branch so the conflicts are resolved ? |
🚀 I would like to ask you all for help in testing and reviewing PR #568 🚀 |
@henrikra @gempain @patrykkrawczyk @maxime1992 @Djaler @ramyothman Could you please test preview release (#568) and provide some feedback? |
@vlapo yes, I'll give it a shot. Actually, had a chance yesterday to try 12.0.0.rc-3 with jest and I had a few issues, but it was not a clean install so I need to see if I can reproduce on a clean install because I am wondering whether the problem was jest. Give me a day or two so I can do this. Thanks for the time you're putting into this, very appreciated. |
@vlapo I've put together a demo repo, and so far I can't get tree shaking to work with @vlapo feel free to use my repo to test out your changes or fork it. Do you want me to add you as a contributor so you can commit there ? |
it's also not tree-shakebale in my project |
Thank you for testing!
@patrykkrawczyk could you test |
@vlapo after updating my tsconfig and upgrading to reafctor 5, it is now tree shakable ! Great job ! |
0.12.0-refactor.5 is tree shakeable in my project. |
@vlapo I think after this, we'll have to refactor the |
@vlapo sure, now people that don't use the phone validator won't get those 400kb, but people that do use it will get those kb, and I find it ackward that the validation logic of the phone validator weighs as much as the entire library. Anyway, that's another matter. |
Of course. We have to inform users about this disadvantage (as a note in docs). Developers can use validatorjs But if someone know replacement for |
BREAKING CHANGE: Validation functions was removed from `Validator` class to enable tree shaking. BEFORE: import {Validator} from "class-validator"; const validator = new Validator(); validator.isNotIn(value, possibleValues); validator.isBoolean(value); AFTER: import {isNotIn, isBoolean} from "class-validator"; isNotIn(value, possibleValues); isBoolean(value); Closes #258, #248, #247, #212
Pls check a part of my bundle graph: Is this normal? I've My tsconfig matches the one from @gempain and my webpack conf is the one from Next + FWIW, this is a Next production build of the client side. I have v0.12.2 of class-validator. |
Class validator uses the phone validator lib from google which makes its
bundle big unfortunately
…On Wed, Jul 8, 2020, 09:30 desmap ***@***.***> wrote:
Pls check my part of my bundle graph:
[image: image]
<https://user-images.githubusercontent.com/43666255/86890019-f69d0a80-c0fc-11ea-9927-3d2f1908a230.png>
Is this normal? I've import { IsMongoId, MaxLength, ArrayMaxSize } from
'class-validator and import { validate } from 'class-validator in my
codebase.
My tsconfig matches the one from @gempain <https://github.com/gempain>
and my webpack conf is the one from Next + usedExports: true and I added "sideEffects":
false" in package.json.
FWIW, his is a Next production build of the client side. I have v0.12.2 of
class-validator.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#258 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAU6KBHIBSWHWGU5M45CV43R2QODFANCNFSM4FUZS6PA>
.
|
@ramyothman should not be the case in most recent versions anymore (treeshakable validators). As you can see in @desmap 's chart, libphonenumber is not in there. I guess he/she is wondering why so many validators are bundled as just 3 were imported. |
Just FYI, the package used for validating phone numbers has been replaced in the current develop branch with a package using the same meta information to validate the phone number but much smaller. |
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. |
I started on better modularization/build size reduction, references:
This means moving most decorators and their respective validation implementation to their own file.
Since this is very tedious work: please review and tell me if this is the way to go.
Nice side-effect: also adds an easy way to validate with just a function (see ValidateBy.ts).