Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import moment.js partial or function

Is there any way to avoid importing the whole library and import only a function or partial of it?

For example with lodash you can do something like this: import has from 'lodash/has';

Example would be:

import moment from 'moment';
moment.months()

I know the latest webpack can handle it automatically, but question is for old webpack (1.0)

like image 652
Shota Avatar asked Apr 01 '17 12:04

Shota


People also ask

Is MomentJS being deprecated?

MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.

Why you dont need moment JS?

You do not need Moment. js if you support newer browsers and if you show dates or datetimes only in your user's timezone. Things are not as easy as they seem, especially if you plan on manually parsing the output from the native APIs.

Why is moment JS so large?

Since the Moment. js package isn't modularized and, per the threads on Github issues, it won't be done as support is ending and they have termed it a legacy project. This is the primary reason behind those large chunks in the build size.

What is moment () in JavaScript?

Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node. js and can be installed using npm.


1 Answers

It's impossible for moment.. You can do some plugin: https://github.com/moment/moment/issues/2373

like image 84
Andrei Ch Avatar answered Nov 15 '22 10:11

Andrei Ch