Moment.js using with Browserify
Last Updated :
28 Mar, 2023
Moment.js is a JavaScript date library for parsing, validating, manipulating, and formatting dates. In this article, we will learn how to use Moment.js with Browserify.
To run the Moment.js program in Browserify, it needs to be installed first using the following command:
npm install moment
Then we need to acquire the plugin in the program so that it is ready to use.
Syntax:
let moment = require('moment');
The below examples will show how to use Moment.js with Browserify along with its configurations.
Example 1: In this example, we include all the locales in Browserify.
Javascript
const moment = require( "moment" );
require( "moment/min/locales.min" );
moment.locale( "es" );
console.log(moment.locale());
|
Output:
es
Example 2: Due to a bug that prevents the loading of the moment.locale, we will use the workaround as shown in this example.
Javascript
const moment = require( "moment" );
moment.locale( "cs" );
console.log(moment.locale());
|
Output:
cs
References: https://momentjs.com/docs/#/use-it/browserify/
Share your thoughts in the comments
Please Login to comment...