Moment.js: only specific localizations

I am looking for a way to enable momentjs with localization (German in my case), but not with all other localizations (mini version 40kb) so that it is slim. Is it possible to exclude all other localizations except one?

+6
source share
1 answer

According to moment.js docs: Downloading locales in a browser requires you to include locale files.

 <script src="moment.js"></script> <script src="locale/fr.js"></script> <script src="locale/pt.js"></script> <script> moment.locale('fr'); // Set the default/global locale // ... </script> 

Also, if you want, you can create a mini version of moment.js complete with the locale of your choice.

 grunt embedLocales --embedLocales de 

Update:

As mentioned in the comments and in accordance with the contribution guide executing this command:

 grunt transpile:fr,ru 

As a result, the user-defined local packages moment-with-locales.custom.js and locales.custom.js inside build/umd/min , containing only French and Russian.

+8
source

Source: https://habr.com/ru/post/980231/


All Articles