Hi, it's a while that I'm using dayjs as it is immuable and the bundle is way smaller (just 4 kb):
https://github.com/iamkun/dayjs
The dayjs API are the same, is there a way to use this library instead of moment.js? Any specific advice or drawback?
moment is the defacto standard for the ecosystem. I don鈥檛 know what locales dayjs supports, but if it鈥檚 any less than moment than it鈥檚 not an option.
Adding this to Webpack saved just over _1 mb_ of unminified code.
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
Was looking into aliasing dayjs for momentjs but ran into errors in some of the default functions like_moment2.default.localeData. Would love a prop of react-dates that suppresses local since sometimes we don't need it and it makes this great package much lighter.
I think everyone needs it; the likelihood that any website is only ever accessed by viewers from one locale is pretty close to zero.
I guess they have locale support: https://github.com/iamkun/dayjs/tree/88548e9738fc3f9334da934a96a3d1af1acb9957/src/locale
See https://github.com/airbnb/react-dates/issues/208#issuecomment-419140310:
I think it鈥檇 be better to wait for the Temporal proposal at this point, and then use a polyfill for it outside of libs like react-dates - that way the bundle size impact would eventually be zero, we鈥檇 get first-class primitives with which we could provide precise validation, and we wouldn鈥檛 have to endure two very difficult breaking changes for what ends up being a relatively small bundle size gain.
Thanks. Actually I had found that other issue after posting this comment. Pretty interesting read. The temporal spec seems really promising!
Just did a quick attempt of replacing moment to dayjs.
According to this article in Day.js https://github.com/iamkun/dayjs/issues/529.
We simply just have to
module.exports = {
resolve: {
alias: {
moment: 'dayjs',
}
}
}
without change a line of code. And all basic demos works fine on my side.
And bundle size reduced from 60kb to 4kb, which is really nice.
^ tried that, mostly works but there are a few functions such as duration, weekday not currently supported in dayjs
I just discovered this project and this interesting topic.
As the maintainer of Day.js, I'm happy to offer some help to this replacement.
I could add the missing functions as a plugin if needed.
Cheers. 馃槵
@majapw please use dayjs 馃槝
Having to integrate with moment is an unnecessary bloat, the maintainers have made little progress towards fixing the ridiculous size of the library, it would be best for the community to move towards a more reasonable alternative
Firstly, thank you for creating/maintaining such an excellent library!
While momentjs was the standard yesterday, doesn't mean it should be today. There are better alternatives to using a bloated library with a mutable API.
I would like to have no momentjs dependency in my clients project, which means I am now considering a react-dates replacement.
Thanks
What should be isn't really relevant; it is the standard, and will remain so until the language's Temporal proposal reaches stage 3, at which point a polyfill for that will become the standard.
As for "bloat", it's not bloated; moment has exactly the i18n/l10n data that's needed.
@ljharb
https://momentjs.com/docs/#/-project-status/
We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.
Temporal is not yet stage 3, but hopefully will be within the next 6 months, and it鈥檚 not worth the effort to migrate to another date library twice.
There is also the option to use something like date-io, which provides a layer of abstraction between common date libraries and the package. That way, this project could use moment, dayjs, date-fns, etc. seamlessly, and avoid future rewrites.
@chris-guidry that seems like an interesting alternative to #1947; but as soon as Temporal is stage 3, I'm not sure why it'd be valuable to support anything else.
We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.
I think now would be a good time to migrate to dayjs
hi , how can i use react-dates without using badMutable plugin ?
any news about migration to dayjs?
Temporal is now stage 3 (altho browsers won鈥檛 be shipping it unflagged just yet), so as soon as there鈥檚 a viable production-level polyfill (at this writing, none exist) react-dates, as well as the rest of the JS ecosystem, should immediately migrate to it instead of moment or dayjs or date-fns etc. Thus, there鈥檇 be no value in migrating react-dates to dayjs or anything else that鈥檚 not Temporal.
Most helpful comment
I just discovered this project and this interesting topic.
As the maintainer of Day.js, I'm happy to offer some help to this replacement.
I could add the missing functions as a plugin if needed.
Cheers. 馃槵