Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment.js: only certain localizations

I am looking for a way to include momentjs with a localization (german in my case), but not with all other localizations (the 40kb minified version), to keep it slim. Is it possible to exclude all other localizations but one specific?

like image 208
Clawish Avatar asked Dec 28 '14 15:12

Clawish


1 Answers

According to moment.js docs : Loading locales in the browser just requires you to include the 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 desire, you can build a minified moment.js version bundled with the locale of your choice.

grunt embedLocales --embedLocales de

Update:

As mentioned in comments and according to the contribution guide running this command :

grunt transpile:fr,ru

Will result in custom locale bundles moment-with-locales.custom.js and locales.custom.js inside build/umd/min containing just French and Russian.

like image 185
Alexander Avatar answered Oct 07 '22 14:10

Alexander