Clawish
Clawish

Reputation: 2964

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?

Upvotes: 6

Views: 3362

Answers (1)

Alexander
Alexander

Reputation: 12785

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.

Upvotes: 8

Related Questions