- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to prevent moment.js from loading locales with webpack?
A local file is a .json file that contains a set of translations for the text strings used in a theme template file. A separate local file is used for every language.
When you require moment.js in your code and pack it with webpack, the bundle size becomes huge because it includes all locale files.
You can remove all locale files using the IgnorePlugin. For example,
Example
const webpack = require('webpack'); module.exports = { plugins: [ // Ignore all locale files of moment.js new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), ], }; // load specific locales in your code. const moment = require('moment'); require('moment/locale/ja'); moment.locale('ja');
When bundling, webpack will only use the locale files for ja. This will greatly reduce the bundle size.
Advertisements