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

Replace momentjs with (much leaner) dayjs #5075

Merged
merged 1 commit into from Apr 7, 2019

Conversation

larsjohnsen
Copy link
Collaborator

@larsjohnsen larsjohnsen commented Feb 13, 2019

Dayjs is modular and extendable. By being selective with what methods and locales are imported, we get a dependency that is less than 20 kB (in contrast to momentjs' 300 kB)

Tested in browser: Chrome 73

@ghost
Copy link

ghost commented Feb 18, 2019

Can't personally vouch for it but have read about Day.Js as an alternative

⏰ Day.js 2KB immutable date library alternative to Moment.js with the same modern API

https://github.com/iamkun/dayjs

reference: moment/moment#2373 (comment)

@larsjohnsen larsjohnsen changed the title momentjs: Only bundle necessary locales Replace momentjs with (much leaner) dayjs Feb 18, 2019
@larsjohnsen
Copy link
Collaborator Author

Thanks for the suggestion, @xxyuk. That seems to fit our use case well!

const dayjs = require('dayjs'); // eslint-disable-line global-require
dayjs.extend(require('dayjs/plugin/relativeTime')); // eslint-disable-line global-require
dayjs.extend(require('dayjs/plugin/localizedFormat')); // eslint-disable-line global-require
dayjs.locale(locale());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, since we can get the locale via locale, maybe we can replace all of the require lines with a single require(`dayjs/locale/${locale()}`); call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Webpack will be able to resolve that without also bundling all locales.

Dayjs is extensible. By being selective methods and locales are imported, we get a dependency that less than 20 kB (in contrast to momentjs' 300 kB)
@larsjohnsen larsjohnsen merged commit 7e44b8b into honestbleeps:master Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants