1.2.0 • Published 4 years ago

moment-locales-webpack-plugin v1.2.0

Weekly downloads
260,805
License
MIT
Repository
github
Last release
4 years ago

moment-locales-webpack-plugin

npm Travis Greenkeeper badge

Easily remove unused Moment.js locales when building with webpack

Why

75% (160 minified KBs)¹ of Moment.js’ size are files used for localization. They are always included when you build your app 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

Install

npm install --save-dev moment-locales-webpack-plugin

Usage

// webpack.config.js
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

module.exports = {
    plugins: [
        // To strip all locales except “en”
        new MomentLocalesPlugin(),

        // Or: To strip all locales except “en”, “es-us” and “ru”
        // (“en” is built into Moment and can’t be removed)
        new MomentLocalesPlugin({
            localesToKeep: ['es-us', 'ru'],
        }),
    ],
};

Plugin Options

localesToKeep: String[]

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.

ignoreInvalidLocales: Boolean

A flag to ignore invalid or unsupported locales in the localesToKeep array.

Be careful! A typo in the localesToKeep array with this flag enabled will silently exclude the desired locale from your bundle.

Related projects

Contributing

See CONTRIBUTING.md for how to contribute.

License

MIT © Ivan Akulov

@commercetools-frontend/mc-scripts@commercetools-docs/gatsby-theme-docsspreadd-storybook@eucalyptusvc/kin-nanosgui-coremariadb-maxscale-query-editormidland-property-detail@ywjt/mpa-builder@ywjt/spa-builder@ywjt/spa-m-builder@infinitebrahmanuniverse/nolb-momhkp-sell-online@everything-registry/sub-chunk-2195front-affilatefrontend-input-packagehare-scripticlickilios-commonmini-checkluna-configmelda-kb-vuelianxi_likeilongemail@rh-support/configspacvuedaterangepacvuedaterangesimplenightscoutpublic-poll-storybooknuxtjs-moment_timezonenuxt-moment-jalaali@zscreate/form-component@bildvitta/biribinhaantduipackage@blueking/bk-report-cli@zalastax/nolb-mom@universityofwarwick/webpack-config-builderreact-front-test-component@tablecheck/scripts@sweexui/weex-cli-service@sweet-weex/weex-cli-service@valcom/v-alert-geolocation-modulereact-app-rewire-moment-locales-plugin@startupjs/bundler@alilc/build-plugin-alta8k@aktiv/cli@zarinpal/web-components@aliedu/e-compalliance-calendarsuncn-im-baseclayclicomponent-send-mailcomponent-send-maillsoogang-build-scriptssparrow-kraken-ng-vue-kitdbl-components@digiforce-cloud/dvd-build-plugin-altvuecompo@fch/webpack-bundle@fgui/build-plugin-alt@feizheng/webpack-app-kitsdm-bundler@elliemae/pui-cli@excitare/cli-config-next@excitare/cli-config-webpack@excitare/builderdmp-cliwhmmantdui@marrow/fish@jswork/webpack-app-kits@jlchain/fe-pack@metamodern.dev/metamodern-ui@mamba-le/plugin-nuxtwwyd@nuxtjs/moment@henderea/static-site-builder@mostlyserious/brightpack@ozo/cra-rewired@packi_/feature-webpack@pretalx/schedule@servicetitan/startup@sever7788/metamodern-ui
1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.1-0

4 years ago

1.1.0

5 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago