I think it's fine.  My only concern would be that we aren't accidentally
using moment.js somewhere for something that date-fns doesn't do.  I
suspect whoever picks up the ticket will figure that out pretty quick
though. ;) . I'm +1 on the move; you convinced me.

On Wed, Sep 26, 2018 at 8:36 AM Tamás Fodor <[email protected]> wrote:

> I'd like to open a discussion about replacing Moment.js
> <https://momentjs.com/> in Alerts UI. date-fns <https://date-fns.org/> has
> almost the same functionality to manipulate date/time in the application.
> Moment.js is a great library but it has a huge footprint in the bundle and
> it's significant when it comes to performance optimization in order to
> decrease the initial load time.
>
> Here you can find a brief introduction of the problem and a few ideas how
> to replace it with date-fns or native functions.
> https://github.com/you-dont-need/You-Dont-Need-Momentjs
>
> *The problem:*
> In order to use Moment.js, we have to import the whole library which has
> significant impact on the size of the production bundle of our javascript
> code.
>
> *A few examples:*
>
> https://github.com/apache/metron/blob/e66cfc80e6a6fa53110c3f2fa8ee0d31ea997bf6/metron-interface/metron-alerts/src/app/utils/utils.ts#L18
>
> https://github.com/apache/metron/blob/ccdbeff5076553382091d4b9423ed48ccdba10ee/metron-interface/metron-alerts/src/app/shared/pipes/time-lapse.pipe.ts#L20
>
> Even though, we have tree-shaking
> <https://webpack.js.org/guides/tree-shaking/> which is a great feature of
> javascript bundlers (in our case Webpack), because of how Moment.js is
> structured, it prevents the bundler from doing tree-shaking properly
> <
> https://github.com/you-dont-need/You-Dont-Need-Momentjs/blob/master/README.md
> >.
> date-fns is just fine with that
> <https://github.com/date-fns/date-fns/issues/275#issuecomment-264934189>.
> For example, to use the `format` functions we don't have to import the
> whole library, we can import only the format function
> <https://date-fns.org/v1.28.0/docs/format#usage> individually.
>
> What do you think?
>
> Tamas
>

Reply via email to