Easily remove unused Moment.js locales when building with webpack
You don’t need most of these files if your app is only available in a few languages. Use this plugin to strip these KBs and optimize the app!
¹ – tested with Moment.js 2.18.1
npm install --save-dev moment-locales-webpack-plugin
// webpack.config.jsconst MomentLocalesPlugin = ;moduleexports =plugins:// To strip all locales except “en”// Or: To strip all locales except “en”, “es-us” and “ru”// (“en” is built into Moment and can’t be removed)localesToKeep: 'es-us' 'ru';
An array of locales to keep bundled (other locales would be removed).
Locale names follow Moment.js behavior – if a specific locale name (e.g.
ru-ru) is absent, but a more generic locale (
ru) is available, the generic one will be kept bundled.
MIT © Ivan Akulov