Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamakulov/moment-locales-webpack-plugin
Easily remove unused Moment.js locales with webpack
https://github.com/iamakulov/moment-locales-webpack-plugin
moment-js webpack webpack-plugin
Last synced: 11 days ago
JSON representation
Easily remove unused Moment.js locales with webpack
- Host: GitHub
- URL: https://github.com/iamakulov/moment-locales-webpack-plugin
- Owner: iamakulov
- Created: 2018-01-17T10:13:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:57:28.000Z (almost 2 years ago)
- Last Synced: 2024-09-07T22:25:33.909Z (2 months ago)
- Topics: moment-js, webpack, webpack-plugin
- Language: JavaScript
- Size: 1.48 MB
- Stars: 435
- Watchers: 6
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
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!
¹ – tested with Moment.js 2.18.1
## 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 © Ivan Akulov