
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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.
- Related Articles
- Creating animated loading skeletons in React JS
- How to create loading buttons with CSS?
- How to Change or Set System Locales in Linux
- How to Design a Moment Marketing Campaign?
- How to Prevent Systems from Phishing Attacks?
- How to Prevent Your Website from Hackers?
- How to prevent form from being submitted?
- How to call the loading function with React useEffect?
- How to stop a page loading from Selenium in chrome?
- How to Prevent Twitter Accounts from being Hacked
- How can I prevent a window from being resized with Tkinter?
- Loading messages from Excel to SAP table T100
- How to show Page Loading div until the page has finished loading?
- How to prevent the screen from sleeping in iOS?
- How to prevent buttons from submitting forms in HTML?

Advertisements