# moment-locales-webpack-plugin

> Strip unused locales from Moment.js

Latest version **1.2.0** (published 2020-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install moment-locales-webpack-plugin
pnpm add moment-locales-webpack-plugin
yarn add moment-locales-webpack-plugin
bun add moment-locales-webpack-plugin
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2020-03-15 |
| First published | 2018-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/moment-locales-webpack-plugin) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 433 |
| Author | Ivan Akulov |
| Maintainers | iamakulov |

## Links

- npm: https://www.npmjs.com/package/moment-locales-webpack-plugin
- Repository: https://github.com/iamakulov/moment-locales-webpack-plugin
- npm.io page: https://npm.io/package/moment-locales-webpack-plugin

## Dependencies (1)

- [lodash.difference](https://npm.io/package/lodash.difference.md) ^4.5.0

## Recent versions

- 1.2.0 (latest) — 2020-03-15
- 1.1.1-0 (beta) — 2019-11-17
- 1.1.2 — 2019-11-18
- 1.1.1 — 2019-11-17
- 1.1.0 — 2019-08-15
- 1.0.7 — 2018-05-23
- 1.0.6 — 2018-05-21
- 1.0.5 — 2018-03-19
- 1.0.4 — 2018-01-21
- 1.0.3 — 2018-01-19
- 1.0.2 — 2018-01-17
- 1.0.1 — 2018-01-17
- 1.0.0 — 2018-01-17

## README

# moment-locales-webpack-plugin

[![npm](https://img.shields.io/npm/v/moment-locales-webpack-plugin.svg)](https://www.npmjs.com/package/moment-locales-webpack-plugin) [![Travis](https://img.shields.io/travis/iamakulov/moment-locales-webpack-plugin.svg)](https://travis-ci.org/iamakulov/moment-locales-webpack-plugin) [![Greenkeeper badge](https://badges.greenkeeper.io/iamakulov/moment-locales-webpack-plugin.svg)](https://greenkeeper.io/)

> Easily remove unused Moment.js locales when building with webpack

## Why

75% (160 minified KBs)¹ of [Moment.js’](https://github.com/moment/moment) size are files used for localization. [They are always included](https://iamakulov.com/notes/webpack-front-end-size-caching/#moment-js) 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!

<small>¹ – tested with Moment.js 2.18.1</small>

## Install

```sh
npm install --save-dev moment-locales-webpack-plugin
```

## Usage

```js
// 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

-   [`moment-timezone-data-webpack-plugin`](https://github.com/gilmoreorless/moment-timezone-data-webpack-plugin) – a plugin optimizing the Moment Timezone library.

## Contributing

See [CONTRIBUTING.md](https://github.com/iamakulov/moment-locales-webpack-plugin/blob/master/CONTRIBUTING.md) for how to contribute.

## License

MIT © <a href="https://iamakulov.com">Ivan Akulov</a>

---
_Source: https://npm.io/package/moment-locales-webpack-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
