Open toshsan opened 3 years ago
Thanks for your suggestion.
I'm 100% in favor of dropping Moment.js
Either using built-in vanilla JavaScript or something like Day.js
Moment.js is very heavyweight.
Hey folks,
For anyone looking to do this, I've just been doing it inside of Laravel Mix. I started with a find/replace for moment() and moment, but then had to bring in the following plugins to fix it.
dayjs = require('dayjs') var LocalizedFormat = require( 'dayjs/plugin/localizedFormat') var localeData = require('dayjs/plugin/localeData') var arraySupport = require("dayjs/plugin/arraySupport"); var isoWeek = require('dayjs/plugin/isoWeek') dayjs.extend(LocalizedFormat) dayjs.extend(localeData) dayjs.extend(arraySupport); dayjs.extend(isoWeek)
Really great that we have an option here.
Thanks for the great work, @alumuko!
I have tried to follow your recommandation and did as follow:
1\ Add in <head />
the following:
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.8/dayjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.8/plugin/localizedFormat.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.8/plugin/localeData.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.8/plugin/arraySupport.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.11.8/plugin/isoWeek.js"></script>
<script>
dayjs.extend(window.dayjs_plugin_localizedFormat)
dayjs.extend(window.dayjs_plugin_localeData)
dayjs.extend(window.dayjs_plugin_arraySupport)
dayjs.extend(window.dayjs_plugin_isoWeek)
</script>
2\ Remove momentjs
from <head />
3\ Replace in vanilla-datetimerange-picker.js
all occurence of moment
with dayjs
4\ Perform tests
During test, it work not well to change month of the calendar, unless I revert this.startDate
to use moment:
- this.startDate = dayjs().startOf('day');
+ this.startDate = moment().startOf('day');
Obviously this is not what I want :)
@JackEllis it would have been nice to share the whole migration process instead of just the plugin installation ^^, this could have been a good contributing PR.
Thanks @alumuko for great work and sharing !
Why Day.js? 2kB
Less JavaScript to download, parse and execute, leaving more time for your code. Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.