joanllenas / ngx-date-fns

⏳ date-fns pipes for Angular
164 stars 14 forks source link

Allow to import pipe selectively #215

Closed unsafecode closed 4 years ago

unsafecode commented 5 years ago

Description of the Issue and Steps to Reproduce:

Looks like the current implementation always imports all the pipe, making the final bundle excessively large:

image

It would be better to be able to import pipes in a more selective way, in order not to increase the final app size including unused code.

Environment:

Please answer the following questions:

joanllenas commented 5 years ago

Hi @unsafecode , thanks for reporting. I'll take a look ASAP.

Cheers!

joanllenas commented 5 years ago

Hi @unsafecode I upgraded to Angular 7 hoping that tree shaking would have been improved somehow but I'm having the same issues.

Not sure if there's something I can do until date-fns v2 is released. Take a look at this: https://github.com/date-fns/date-fns/blob/master/docs/esm.md

Suggestions / PRs are welcomed!

gmanoj26 commented 4 years ago

@joanllenas : As date-fns v2 is released. do we have any update on this open issue.

joanllenas commented 4 years ago

Hi @gmanoj26 , I took a look a while ago and didn't find a solution to the problem. V2 by itself didn't solve the issue. Maybe, for this to work we need something like what this article suggests; one pipe per module; but I think it's not a good idea given the number of pipes this library contains.

I'm open to discussing possible solutions if someone has the time to investigate.

joanllenas commented 4 years ago

I added a section about tree shaking in the docs. I hope this helps: https://github.com/joanllenas/ngx-date-fns#tree-shaking-date-fns

KingDarBoja commented 4 years ago

In order to make each pipe tree-shakable, those must be provided as secondary entry points (as stated by the article, 1 pipe per entry point / module). It can be easily done using ng-samurai schematics.

Willing to look into this as I am using this library but not being tree-shakable atm.